-
Notifications
You must be signed in to change notification settings - Fork 0
/
ads_prepare.py
78 lines (64 loc) · 2.12 KB
/
ads_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
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_ads():
output_html = os.environ.get("output_data")
teporary_file = os.environ.get("teporary_file")
input_data = os.environ.get("input_data")
file_kw = os.environ.get("file_kw")
#creazione Cartelle
config_file = 'config_file'
# if not os.path.exists(output_screenshot):
# os.makedirs(output_screenshot)
#
#
# File
#file_kw = input_data+'/keywords.txt'
db_name_keyword = os.environ.get("db_name_keyword_ads")
#
#
# Creazione dataframe keyword
dataframe = pd.read_csv(file_kw, encoding='utf-8', sep='\t', header=None, low_memory=False)
#print(dataframe)
dataframe = dataframe.iloc[:, 0]
#print(dataframe)
dataframe = dataframe.to_frame().reset_index(drop=True)
#print(dataframe)
dataframe = dataframe.iloc[1:]
#print(dataframe)
#print(type(dataframe))
#print(dataframe)
#print(dataframe.info())
#dataframe = pd.read_csv(file_kw, encoding='utf-8', sep=';', header=None)
#print(dataframe)
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_ads()