-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_download.py
71 lines (56 loc) · 1.91 KB
/
auto_download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import datetime
import psycopg2
import Estabelecimentos
import Profissionais
import cns_cpf_update
def main():
print('Inicializando o processo de busca da competência atual')
def GetCompetencia(): #Pega a competência referente ao último mÊs
today = datetime.date.today()
month = today.month
year = today.year
competencia = 202210
if month == 1:
month = 12
year -= 1
else:
month -= 1
if month < 10:
competencia = str(year) + '0' + str(month)
else:
competencia = str(year) + str(month)
return(competencia)
competencia = GetCompetencia()
def GetEstabLastCompetency():
conn = psycopg2.connect(
dbname = '',
user = '',
password = '',
port = '',
host = ''
)
cur = conn.cursor()
cur.execute('SELECT competencia FROM cnesEstabelecimentos LIMIT 1')
last_competencia = cur.fetchone()
return last_competencia
estab_last_competencia = GetEstabLastCompetency()[0]
if competencia != estab_last_competencia:
Estabelecimentos.main(competencia)
def GetProfLastCompetency():
conn = psycopg2.connect(
dbname = '',
user = '',
password = '',
port = '',
host = ''
)
cur = conn.cursor()
cur.execute('SELECT competencia FROM cnesProfissionais LIMIT 1')
last_competencia = cur.fetchone()
return last_competencia
prof_last_competencia = GetProfLastCompetency()
if competencia != prof_last_competencia:
Profissionais.main(competencia)
cns_cpf_update.main(competencia)
if __name__ == '__main__':
main()