123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- '''Created May 25, 2022 deeejas'''
- # coding: UTF-8
- import re
- from time import sleep
- import requests
- import gspread
- from gspread import BackOffHTTPClient
- from bs4 import BeautifulSoup
- # g_sheet = '1JW9MyYjZjyLMKtj4bwanq5VbUWaIF0RhZjbQQFd2YFQ' # MZK
- g_sheet = '1DUWx4q3MR6YlLkPhXSUWJb_7MjFia13ee5z0mXgq-X8' # FER
- # g_sheet = '1jBc-DottcmtttoDFRMdsVVp6nbEmq4ficd58XFy4x-o'
- gc = gspread.service_account(filename='Pysheet26134-2daf66659e50.json', http_client=BackOffHTTPClient) # MZK+FER
- # gc = gspread.service_account(filename='Pysheet26134-2daf66659e50.json', http_client=BackOffHTTPClient)
- gsh = gc.open_by_key(g_sheet)
- sh1 = gsh.worksheet('PJ')
- col_CUI = sh1.col_values(2)[3:]
- col_MESSAGE = sh1.col_values(10)[3:]
- col_INDEX = sh1.col_values(4)[3:]
- cond_range = zip(col_CUI, col_MESSAGE, col_INDEX)
- def state_decl(decl_id: str, vat: str):
- payload = {
- 'id': decl_id,
- 'cui': vat}
- headers = {
- 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.61 Safari/537.36',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept': '*/*',
- 'Connection': 'keep-alive'}
- url = 'https://www.anaf.ro/StareD112/vizualizareStare.do'
- resp = requests.post(url, data=payload, headers=headers)
- print(resp.status_code)
- html = resp.content
- soup = BeautifulSoup(html, 'html.parser')
- message = []
- for tag in soup.find_all('tr', align='left'):
- # print(tag.find_all('td'))
- for child in tag.find_all('td'):
- child = child.get_text().strip()
- message.append(child)
- start = message.index(decl_id)
- message = message[start:start + 6]
- search_str = soup.find_all('td', valign='top')[0].get_text()
- cui = re.search('(?<=cui: )[0-9]*', search_str).group()
- message.insert(0, cui)
- print(message)
- # sleep(1)
- return message
- if __name__ == '__main__':
- for cui, message, index_ in cond_range:
- # print(message)
- condition = cui != '' and message == 'F'
- print(condition)
- if condition:
- state = state_decl(decl_id=index_, vat=cui)
- sleep(1)
- cell = sh1.find(index_, in_column=4)
- sh1.update_cell(cell.row, col=10, value=state[3])
- sh1.update_cell(cell.row, col=5, value=state[2])
- sh1.update_cell(cell.row, col=7, value=state[6])
|