-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStars4All_App.py
143 lines (114 loc) · 5.79 KB
/
Stars4All_App.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from ast import Del
from datetime import datetime
from os import remove
import CSV_ZENODO
from CSV_ZENODO import Upload_Zenodo
import zipfile
import shutil
import os
import datetime
from Data_Extraction_funtions import work_flow
from Data_Extraction_funtions import date_automathic
import sys
from Stars4all import stars4all_filtrado
from Stars4all2 import stars4all_filtrado2
from datetime import datetime
#Pricipal Funtion, it iniciate all funtions and create all variables,
# it has the job to download the csv, filter them, create paths to save the data,
# and send them to the zenodo profile
def Stars4all_app(start, final):
#This part creates a name out of the start time, so we can use it as title for the csv
date_time_obj = datetime.strptime(start ,'%Y-%m-%dT%H:%M:%SZ')
name= date_time_obj.strftime('%Y-%B')
#variables used for uploading the files to zenodo
Access_Token = 'y87XNFfmcYaGavtqRg119DXg78qxKzVyHqVlqHR4ckdDUiFlaUCrJza3pMml'
Filename_Row = 'STAR4ALL-Row-%s' % name
Filename_Final = 'STAR4ALL-Final-%s' % name
Filename_Mensual = 'STARS4ALL-%s.csv' % name
#variables needed for the mata_data cration later on
Title_Row = 'STAR4ALL_%s_Row' % name
Title_Final = 'STAR4ALL_%s_Final' % name
Title_Mensual = 'STAR4ALL_%s_Mensual' % name
Description = 'Tester for Stars4All'
name_creator = 'STARS4ALL'
Affiliation = 'STARS4ALL'
Type = 'poster'
#Meta_data for every uploading file at zenodo
meta_data_Row = {
'metadata': {
'title': Title_Row,
'upload_type': Type,
'description': Description,
'creators': [{'name': name_creator,
'affiliation': Affiliation}] } }
meta_data_Final = {
'metadata': {
'title': Title_Final,
'upload_type': Type,
'description': Description,
'creators': [{'name': name_creator,
'affiliation': Affiliation}] } }
meta_data_Mensual = {
'metadata': {
'title': Title_Mensual,
'upload_type': Type,
'description': Description,
'creators': [{'name': name_creator,
'affiliation': Affiliation}] } }
#Declaration of the funtions that will be needed
#This funtion Creates files so we can store the CSVs there and have a more clean Disk
#thi will help later to create zip files
def Create_Files():
os.mkdir("/home/osoc22/Final")
os.mkdir("/home/osoc22/Raw")
#This funtion transform the files created before to zip, so we can send them to zanodo more easelly
def File_Zip(Filename):
shutil.make_archive("/home/osoc22/Star4All-FinalData-%s" % Filename, "zip", "/home/osoc22/Final")
shutil.make_archive("/home/osoc22/Star4All-RawData-%s" % Filename, "zip", "/home/osoc22/Raw")
#This funtion incorporate all the callings to the zenodo api to upload the files
def UPload_files():
Upload_Zenodo(Access_Token, meta_data_Row, path_row, Filename_Row)
Upload_Zenodo(Access_Token, meta_data_Final, path_final, Filename_Final)
Upload_Zenodo(Access_Token, meta_data_Mensual, path_mensual, Filename_Mensual)
#Funtion that allows to delete the files and zip that we created before,
# this helps clean the computer and not stack unecessary data
def Delete_files(name):
remove("/home/osoc22/Star4All-RawData-%s.zip" % name)
remove("/home/osoc22/Star4All-FinalData-%s.zip" % name)
shutil.rmtree("/home/osoc22/Final")
shutil.rmtree("/home/osoc22/Raw")
remove("/home/osoc22/STARS4ALL-%s.csv" % name)
#Calling of the funtion that creates the files for the CSV
Create_Files()
#calling of the funtion that downloads the data from the data_base, and send it to the paths
work_flow(start, final,"/home/osoc22/Raw/" ,"/home/osoc22/")
print('Se genera los dataset raw')
contenido = os.listdir('/home/osoc22/Raw')
#print(contenido)
#for i in contenido:
#print(i)
#stars4all_filtrado2('/home/osoc22/Raw/'+ i, "/home/osoc22/Final")
stars4all_filtrado('/home/osoc22/'+'STARS4ALL-'+ name +'.csv', '/home/osoc22/Final')
print('Se genera los dataset filtrado')
#Calling of the funtion that transform the files to zips
File_Zip(name )
#creation of the path to the zips created before
path_row = "/home/osoc22/Star4All-RawData-%s.zip" % name
path_final = "/home/osoc22/Star4All-FinalData-%s.zip" % name
#Creation of the path for the mensual CSV
path_mensual = "/home/osoc22/STARS4ALL-%s.csv" % name
#Calling of the funtion that uploads the files to the zenodo account
UPload_files()
print('Calling of the funtion that uploads the files to the zenodo account')
#calling of the funtion that daletes the files and the zips
Delete_files(name)
print('calling of the funtion that daletes the files and the zips')
#End of the funtion
#This part allows us to choose if we want to Call the funtion automatic or manual,
# in case it doesnt work automatic
if __name__ == "__main__":
if(len(sys.argv) == 3):
Stars4all_app(sys.argv[1], sys.argv[2])
else:
final_automatic , start_automatic = date_automathic()
Stars4all_app(start_automatic, final_automatic)