Advertisement
renix1

Automate a task :D

Jan 12th, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.67 KB | None | 0 0
  1. from datetime import datetime
  2. import pyautogui as pyag
  3. import webbrowser
  4. import logging
  5. import time
  6. import os
  7.  
  8. logging.basicConfig(level=logging.INFO)
  9.  
  10. def current_tab():
  11.     logging.info('Checking page elements...')
  12.     current_tab_var = pyag.locateOnScreen('logo.png', grayscale=True)
  13.     if current_tab_var:
  14.         logging.info('Netlifx login page is opened')
  15.         return True
  16.     else:
  17.         logging.info('Netflix login page is not opened')
  18.         quit(0)
  19.  
  20.  
  21. def enter_datas(fname):
  22.     def enter_user(user=''):
  23.         x, y = pyag.locateCenterOnScreen('mail.png', grayscale=True)
  24.         if not x and not y:
  25.             logging.info("coordinates not are correct")
  26.         pyag.click(x, y-5, button='left')
  27.         if len(user) > 1:
  28.             logging.info('Entering user info...')
  29.             logging.info(user)
  30.             pyag.typewrite(user)
  31.         else:
  32.             pyag.hotkey('ctrl', 'a')
  33.  
  34.  
  35.     def enter_pass(password=''):
  36.         x, y = pyag.locateCenterOnScreen('pass.png', grayscale=True)
  37.         if not x and not y:
  38.             logging.info("coordinates not are correct")
  39.         pyag.click(x, y-5, button='left')
  40.         if len(password) > 1:
  41.             logging.info('Entering pass info...')
  42.             logging.info(password)
  43.             pyag.typewrite(password)
  44.         else:
  45.             pyag.hotkey('ctrl', 'a')
  46.             pyag.press('delete')
  47.  
  48.  
  49.     def click_enter():
  50.         logging.info('Submiting datas...')
  51.         x, y = pyag.locateCenterOnScreen('enter.png', grayscale=True)
  52.         pyag.click(x, y, button='left')
  53.         logging.info('Button <enter> clicked')
  54.  
  55.     def check_entered():
  56.         logging.info('Checking if user is logged')
  57.         enter_status = pyag.locateOnScreen('arrow.png', grayscale=True)
  58.         print(enter_status)
  59.         if enter_status:
  60.             logging.info('Checked. User is loged!')
  61.             logging.info("User: %s\nPass: %s\n" % (user, password))
  62.         else:
  63.             pass
  64.     logging.info('Opening file with users and passwords')
  65.     with open(fname) as f:
  66.         lines = f.readlines()
  67.         for l in lines:
  68.             l = l.replace('\n', '')
  69.             user = l[:l.find(':'):]
  70.             password = l[l.find(':')+1::]
  71.             # ERASING TEXT AREAS
  72.             enter_user()
  73.             enter_pass()
  74.             # SUBMITING VALID DATAS
  75.             enter_user(user)
  76.             time.sleep(.3)
  77.             enter_pass(password)
  78.             time.sleep(.3)
  79.             click_enter()
  80.             check_entered()
  81.  
  82. def check_files_today():
  83.     now = datetime.now()
  84.     fname_today = "%s-%s" % (str(now.day).zfill(2), str(now.month).zfill(2))
  85.     print(fname_today)
  86.     if os.path.exists(fname_today):
  87.         logging.info('Existe um arquivo com esse nome')
  88.         return fname_today
  89.     else:
  90.         logging.info('Não existe um arquivo com esse nome')
  91.         fname = input("Nome do arquivo: ")
  92.         return fname
  93.  
  94.  
  95. def main():
  96.     fname = check_files_today()
  97.     current_tab()
  98.     enter_datas(fname)
  99.  
  100. if __name__ == "__main__":
  101.     try:
  102.         main()
  103.     except KeyboardInterrupt:
  104.         print('')
  105.         logging.info('Exiting')
  106.         quit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement