sel_download.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from selenium import webdriver
  2. from selenium.webdriver import ChromeOptions
  3. # from selenium.webdriver.common.keys import Keys
  4. from time import sleep
  5. # from captcha_solver import CaptchaSolver
  6. from receipt import Receipts
  7. # from PIL import Image
  8. # from subprocess import check_output
  9. from datetime import date, datetime, timedelta
  10. import platform as pt
  11. # import pyautogui as ag
  12. # import pytesseract
  13. import os
  14. if pt.system() == 'Linux':
  15. cache_folder = '/home/deeejas/_sel_cache_/'
  16. else:
  17. cache_folder = 'c:/_sel_cache_/'
  18. # solver = CaptchaSolver('browser')
  19. # receipts = Receipts()
  20. chrome_options = ChromeOptions()
  21. prefs = {"profile.default_content_setting_values.notifications": 2}
  22. chrome_options.add_experimental_option("prefs", prefs)
  23. chrome_options.add_argument('--disable-infobars')
  24. chrome_options.add_argument('user-data-dir={0}'.format(cache_folder))
  25. driver = webdriver.Chrome(chrome_options=chrome_options)
  26. class MyReceipts(Receipts):
  27. def __init__(self):
  28. self.url = 'https://www.anaf.ro/StareD112/ObtineRecipisa?numefisier='
  29. def r_downloader(self, _ext='.pdf', cond1=4, cond2=6):
  30. # Receipts.r_downloader(self, _ext, cond1=cond1, cond2=cond2)
  31. my_path = os.getcwd().split('\\')[-1:]
  32. print('my_path', my_path)
  33. my_month = datetime.today() - timedelta(days=datetime.today().day)
  34. date_l = []
  35. if date.today().month < 10:
  36. date_l.append('%s 0%s' % (date.today().year, my_month.month))
  37. else:
  38. date_l.append('%s %s' % (date.today().year, my_month.month))
  39. print('date_l', date_l)
  40. sel = input('type c for current month or s to select month')
  41. mth_yr = '%s-%s' % (date(1900, my_month.month, 28).strftime('%b'), date.today().year)
  42. print('mth_yr', mth_yr)
  43. if sel == 'c':
  44. if my_path == date_l:
  45. for i, k in self.cond_range(cond1, cond2):
  46. if i != '' and k == mth_yr:
  47. driver.get(self.url + i + _ext)
  48. sleep(3)
  49. elif sel == 's':
  50. m = input('Mmm-YYY')
  51. for i, k in self.cond_range(cond1, cond2):
  52. if i != '' and k == m:
  53. driver.get(self.url + i + _ext)
  54. sleep(3)
  55. receipts = MyReceipts()
  56. receipts.get_gspread('Pygsheet-4a83fcaf2282.json', 'Recipisa-2019')
  57. driver.get('https://www.anaf.ro/StareD112/')
  58. input('send captcha, press enter')
  59. receipts.r_downloader(cond1=4, cond2=6)
  60. sleep(300)
  61. driver.close()
  62. # pytesseract.pytesseract.tesseract_cmd = "C:/Program Files/Tesseract-OCR/tesseract.exe"
  63. # print(pytesseract.image_to_string('captcha.png', output_type='data.frame'))
  64. # ag.screenshot('captcha.png', region=(0, 0, 974, 1057))
  65. # raw_data = open('captcha.png', 'rb').read()
  66. # print(solver.solve_captcha(raw_data))