Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import httplib, urllib, json, re, getpass, operator
- class DailyBooth:
- domain = 'dailybooth.com'
- id, username, password = 0, '', ''
- def loop(self):
- print '' # new line? -.-
- commands = {'1': 'Login', '2': 'Dashboard', '3': 'Upload photo', '4': 'Logout', '5': 'Login check', '9': 'Exit'}
- map(operator.itemgetter(0),commands) # right order? werid stuff -.-
- for num, item in sorted(commands.iteritems()):
- print num + ': ' + item
- try:
- action = int(raw_input('What do you want to do? '))
- except:
- action = 0
- print '' # new line? -.-
- if action == 0:
- print 'Invalid command'
- if action == 1:
- uname = raw_input('Username: ')
- pword = getpass.getpass('Password: ')
- if self.login(uname,pword):
- print 'Logged in!'
- else:
- print 'Login failed..'
- if action == 2:
- self.dashboard()
- if action == 3:
- print 'Soon..'
- if action == 4:
- print 'Soon..'
- if action == 5:
- if self.logged_in():
- print 'Yes, you are logged in.'
- else:
- print 'No, you are not logged in'
- if action == 9:
- self.loop = False
- def login(self, username, password):
- print 'Logging in...'
- h = httplib.HTTPConnection(self.domain)
- param = urllib.urlencode({'do': 'login', 'submit': 'Sign In', 'username': username, 'password': password})
- header = {"Content-type": "application/x-www-form-urlencoded",
- "Accept": "text/plain"}
- h.request("POST", "/login?ajax", param, header)
- response = h.getresponse()
- if response.status == 200:
- content = response.read()
- jsc = json.loads(content)
- print jsc['message']
- if jsc['success'] == 1:
- cookies = response.getheader('set-cookie')
- self.cookie = cookies;
- self.id = re.search("user_id=(\d+);", cookies).groups()[0]
- self.username = re.search("username=([a-zA-Z0-9]+);", cookies).groups()[0]
- self.password = re.search("password=([a-zA-Z0-9]+);", cookies).groups()[0]
- return True
- return False
- def logged_in(self):
- try:
- if self.id != 0 and self.username != '' and self.password != '':
- return True
- else:
- return False
- except:
- return False
- def dashboard(self):
- if self.logged_in():
- print 'Dashboard'
- h = httplib.HTTPConnection(self.domain)
- h.putrequest("GET", "/dashboard")
- h.putheader('Cookie','user_id=' + self.id + '; username=' + self.username + '; password=' + self.password + ';')
- h.endheaders()
- response = h.getresponse()
- if response.status == 200:
- content = response.read()
- if re.search("<title>An Error has Occurred<\/title>", content): #doesn't work yet..
- print 'Something went wrong..'
- else:
- print 'Dashboard here..'
- else:
- print 'Failed retreiving dashboard..'
- else:
- print 'You have to be logged in to view the dashboard!'
- print 'DailyBooth v0.1 - by Michael Owens'
- db = DailyBooth()
- while db.loop != False:
- db.loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement