Guest User

asd

a guest
Feb 27th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.96 KB | None | 0 0
  1. try:
  2.     import os
  3. except:
  4.     print("failed to import os")
  5.     exit()
  6.  
  7. try:
  8.     import os.path
  9. except:
  10.     print("failed to import os.path")
  11.     exit()
  12.  
  13. try:
  14.     import sys
  15. except:
  16.     print("failed to import sys")
  17.     exit()
  18.  
  19. try:
  20.     import time
  21. except:
  22.     print("failed to import time")
  23.     exit()
  24.  
  25. try:
  26.     import getpass
  27. except:
  28.     print("failed to import getpass")
  29.     exit()
  30.  
  31. if sys.version_info[0] < 3:
  32.     print("You must be using Python 3")
  33.     exit()
  34.  
  35. try:
  36.     import praw
  37. except:
  38.     print("Praw is not installed. You can install it with pip3:\n>>> pip3 install praw")
  39.     exit()
  40.  
  41. if os.path.exists("first_run") != True:
  42.     print("First time. Redditerminal setup...\n")
  43.     time.sleep(1)
  44.     print("=== INSTRUCTIONS ===")
  45.     print("First, go here: https://www.reddit.com/prefs/apps/")
  46.     print("Then, scroll down and select 'create an app...'")
  47.     print("1. Set Name to 'redditerminal'")
  48.     print("2. Set Description to whatever you want")
  49.     print("3. Select the 'script' radio button")
  50.     print("4. Redirect URI can be a url of your choice.")
  51.     print("   for example, set it to:\n   http://localhost/")
  52.     print("4.1. Leave the About URL blank")
  53.     print("5. Press 'create app'\n")
  54.     print("What is your client id? (it is below the text, 'personal use script',\n                                   which is below your programs Name)")
  55.     clientid = input(">>> ")
  56.     print("\nWhat is your client secret?")
  57.     clientsecret = input(">>> ")
  58.     print("\nStoring information...")
  59.     os.system("mkdir first_run")
  60.     file = open("clientid.cfg","w")
  61.     file.write(clientid)
  62.     file.close()
  63.     file = open("clientsecret.cfg","w")
  64.     file.write(clientsecret)
  65.     file.close()
  66.     print("\nDone! Please re-start the program.")
  67.     exit()
  68.  
  69. try:
  70.     file = open("clientid.cfg", "r")
  71.     clientid2 = file.read()
  72.     file = open("clientsecret.cfg", "r")
  73.     clientsecret2 = file.read()
  74. except:
  75.     print("Could not find file(s) and display the text. Something is broken...")
  76.     exit()
  77.  
  78. username = input("Username: ")
  79. passwd = getpass.getpass()
  80.  
  81. try:
  82.     reddit = praw.Reddit(client_id=clientid2, client_secret=clientsecret2, username=username, password=passwd, user_agent='redditerminal by /u/'+username)
  83. except:
  84.     print("Your clientid or clientsecret might've mistakenly been wrong.\n")
  85.     choice = input("Delete files (y/n)? ")
  86.     if choice == "y" or choice == "yes" or choice == "sure" or choice == "ye" or choice == "yess" or choice == "yyes" or choice == "yees" or choice == "yeess" or choice == "yyees" or choice == "yyeess" or choice == "yee" or choice == "yep" or choice == "yesh": #yesh is something only sudolinux would say... lol
  87.         choice = input("Windows or Linux[or mac] (w,l)? ")
  88.         if choice == "windows" or choice == "w" or choice == "win" or choice == "wind" or choice == "window" or choice == "windows 10" or choice == "windows 8" or choice == "windows 7" or choice == "windows xp" or choice == "windows vista" or choice == "windows 2000": #oh the memories.. jk, linux rules
  89.             print("Deleting...")
  90.             os.system("del clientid.cfg")
  91.             os.system("del clientsecret.cfg")
  92.             os.system("rmdir first_run")
  93.             print("Please re-run the program to enter setup again.")
  94.             exit()
  95.         else:
  96.             print("Deleting...")
  97.             os.system("rm -rf clientid.cfg")
  98.             os.system("rm -rf clientsecret.cfg")
  99.             os.system("rm -rf first_run")
  100.             print("Please re-run the program to enter setup again.")
  101.             exit()
  102.     else:
  103.         print("Ok. Exiting...")
  104.         exit()
  105.  
  106. try:
  107.     user = reddit.user.me()
  108.     print("You are logged in as",user)
  109. except:
  110.     print("Failed to Login. 1/3 Attempts")
  111.     username = input("\nUsername: ")
  112.     passwd = getpass.getpass()
  113.     try:
  114.         reddit = praw.Reddit(client_id=clientid2, client_secret=clientsecret2, username=username, password=passwd, user_agent='redditerminal by /u/'+username)
  115.     except:
  116.         print("Your clientid or clientsecret might've mistakenly been wrong.\n")
  117.         choice = input("Delete files (y/n)? ")
  118.         if choice == "y" or choice == "yes" or choice == "sure" or choice == "ye" or choice == "yess" or choice == "yyes" or choice == "yees" or choice == "yeess" or choice == "yyees" or choice == "yyeess" or choice == "yee" or choice == "yep" or choice == "yesh": #yesh is something only sudolinux would say... lol
  119.             choice = input("Windows or Linux[or mac] (w,l)? ")
  120.             if choice == "windows" or choice == "w" or choice == "win" or choice == "wind" or choice == "window" or choice == "windows 10" or choice == "windows 8" or choice == "windows 7" or choice == "windows xp" or choice == "windows vista" or choice == "windows 2000": #oh the memories.. jk, linux rules
  121.                 print("Deleting files...")
  122.                 os.system("del clientid.cfg")
  123.                 os.system("del clientsecret.cfg")
  124.                 os.system("rmdir first_run")
  125.                 print("Please re-run the program to enter setup again.")
  126.                 exit()
  127.             else:
  128.                 print("Deleting files...")
  129.                 os.system("rm -rf clientid.cfg")
  130.                 os.system("rm -rf clientsecret.cfg")
  131.                 os.system("rm -rf first_run")
  132.                 print("Please re-run the program to enter setup again.")
  133.                 exit()
  134.         else:
  135.             print("Ok. Exiting...")
  136.             exit()
  137.     try:
  138.         user = reddit.user.me()
  139.         print("You are logged in as",user)
  140.     except:
  141.         print("Failed to Login. 2/3 Attempts")
  142.         username = input("\nUsername: ")
  143.         passwd = getpass.getpass()
  144.         try:
  145.             reddit = praw.Reddit(client_id=clientid2, client_secret=clientsecret2, username=username, password=passwd, user_agent='redditerminal by /u/'+username)
  146.         except:
  147.             print("Your clientid or clientsecret might've mistakenly been wrong.\n")
  148.             choice = input("Delete files (y/n)? ")
  149.             if choice == "y" or choice == "yes" or choice == "sure" or choice == "ye" or choice == "yess" or choice == "yyes" or choice == "yees" or choice == "yeess" or choice == "yyees" or choice == "yyeess" or choice == "yee" or choice == "yep" or choice == "yesh": #yesh is something only sudolinux would say... lol
  150.                 choice = input("Windows or Linux[or mac] (w,l)? ")
  151.                 if choice == "windows" or choice == "w" or choice == "win" or choice == "wind" or choice == "window" or choice == "windows 10" or choice == "windows 8" or choice == "windows 7" or choice == "windows xp" or choice == "windows vista" or choice == "windows 2000": #oh the memories.. jk, linux rules
  152.                     print("Deleting...")
  153.                     os.system("del clientid.cfg")
  154.                     os.system("del clientsecret.cfg")
  155.                     os.system("rmdir first_run")
  156.                     print("Please re-run the program to enter setup again.")
  157.                     exit()
  158.                 else:
  159.                     print("Deleting...")
  160.                     os.system("rm -rf clientid.cfg")
  161.                     os.system("rm -rf clientsecret.cfg")
  162.                     os.system("rm -rf first_run")
  163.                     print("Please re-run the program to enter setup again.")
  164.                     exit()
  165.             else:
  166.                 print("Ok. Exiting...")
  167.                 exit()
  168.         try:
  169.             user = reddit.user.me()
  170.             print("You are logged in as", user)
  171.         except:
  172.             print("Failed to Login. 3/3 Attempts. Giving up.")
  173.             exit()
  174.  
  175. print("Login success!\n")
  176. print("Welcome to Redditerminal v0.1! Type 'h' for help!")
  177. while(1):
  178.     print("This build is just an example to get login working.") # remove this message
  179.     opt = input(">>> ")
  180.  
  181.     if opt == "help" or opt == "h" or opt == "stuck" or opt == "?" or opt == "h?" or opt == "help?":
  182.         print("\aBasic Commands:")
  183.         print("nothing")
Add Comment
Please, Sign In to add comment