-
Notifications
You must be signed in to change notification settings - Fork 0
/
z_trends_prepare.py
108 lines (93 loc) · 3.18 KB
/
z_trends_prepare.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os, time, sqlite3, random
import pandas as pd
from pandas import DataFrame
from datetime import datetime
from os import path
from dotenv import load_dotenv
load_dotenv()
def create_db_and_folder():
output_html = os.environ.get("output_trends")
teporary_file = os.environ.get("teporary_file")
input_data = os.environ.get("input_data")
file_kw = input_data+os.environ.get("kw_file")
#creazione Cartelle
config_file = 'config_file'
if not os.path.exists(output_html):
os.makedirs(output_html)
# if not os.path.exists(output_screenshot):
# os.makedirs(output_screenshot)
if not os.path.exists(teporary_file):
os.makedirs(teporary_file)
test_proxy = 'output_html/test_proxy.txt'
#
#
# File
#file_kw = input_data+'/keywords.txt'
file_proxies = os.environ.get("file_proxies")
db_name_keyword = os.environ.get("db_name_keyword")
db_name_proxy = os.environ.get("db_name_proxy")
#
#
# Creazione dataframe proxy
dataframe = pd.read_csv(file_proxies, encoding='utf-8', header=None)
#timestr = time.strftime('%Y-%m-%d %H:%M:%S')
timestr_now = str(datetime.now())
#print(timestr_now)
timestr = datetime.fromisoformat(timestr_now).timestamp()
#print(timestr)
dataframe['TIME'] = timestr
dataframe.columns = ['PROXY','TIME']
#print(dataframe)
#
#
# Creazione DB da Dataframe PROXY
check_db = path.exists(db_name_proxy)
#print(check_db)
if check_db == False:
conn = sqlite3.connect(db_name_proxy,detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
c = conn.cursor()
c.execute('CREATE TABLE PROXY_LIST (PROXY text, TIME timestamp)')
conn.commit()
df = DataFrame(dataframe, columns= ['PROXY','TIME'])
df.to_sql('PROXY_LIST', conn, if_exists='replace', index = True)
c.execute('''
SELECT * FROM PROXY_LIST
''')
# for row in c.fetchall():
# print(row)
del df
del dataframe
conn.close()
else:
print('DB già presente PROXY')
#
#
# Creazione dataframe keyword
dataframe = pd.read_csv(file_kw, encoding='utf-8', sep=';', header=None)
dataframe['CHECKING'] = 0
dataframe['SUM'] = 0
dataframe.columns = ['KEYWORDS','CHECKING','SUM']
#print(dataframe)
#
#
# Creazione DB da Dataframe KEYWORD
check_db = path.exists(db_name_keyword)
#print(check_db)
if check_db == False:
conn = sqlite3.connect(db_name_keyword)
c = conn.cursor()
c.execute('CREATE TABLE KEYWORDS_LIST (KEYWORDS text, CHECKING number, SUM number)')
conn.commit()
df = DataFrame(dataframe, columns= ['KEYWORDS', 'CHECKING', 'SUM'])
df.to_sql('KEYWORDS_LIST', conn, if_exists='replace', index = True)
c.execute('''
SELECT * FROM KEYWORDS_LIST
''')
#for row in c.fetchall():
# print(row)
del df
del dataframe
conn.close()
else:
print('DB già presente KEYWORDS')
#create_db_and_folder()