-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
65 lines (45 loc) · 1.76 KB
/
main.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
import subprocess
import datetime
import pathlib
root_path = pathlib.Path(__file__).parent.absolute()
now = datetime.datetime.now().strftime('%Y_%m_%d')
news_sites_uids = ['vanguardia']
def main():
_extract()
_transform()
_load()
def _extract():
global root_path
global now
for news_site in news_sites_uids:
filename = '{0}_{1}_articles.csv'.format(news_site, now)
final_destination = r'{0}\{1}\ '.format(root_path, 'transform')
origin = r'{0}\{1}\{2} '.format(root_path, 'extract', filename)
subprocess.run(['python', 'extract.py', news_site], cwd='./extract')
_copy_files(origin, final_destination)
def _copy_files(origin, final_destination):
subprocess.call('copy {0} {1}'.format(
origin, final_destination), shell=True)
subprocess.call('del {0}'.format(origin), shell=True)
def _transform():
global root_path
global now
for news_site in news_sites_uids:
extract_data_file = '{0}_{1}_articles.csv'.format(news_site, now)
transform_data_file = '{0}_{1}_articles_transform.csv'.format(
news_site, now)
final_destination = r'{0}\{1}\ '.format(root_path, 'load')
origin = r'{0}\{1}\{2} '.format(
root_path, 'transform', transform_data_file)
subprocess.run(
['python', 'transform.py', extract_data_file], cwd='./transform')
_copy_files(origin, final_destination)
def _load():
global now
for news_site in news_sites_uids:
transform_data_file = '{0}_{1}_articles_transform.csv'.format(
news_site, now)
subprocess.run(
['python', 'load.py', transform_data_file], cwd='./load')
#subprocess.call('del {0}'.format(transform_data_file), shell=True)
main()