-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreceiver.py
More file actions
32 lines (22 loc) · 858 Bytes
/
receiver.py
File metadata and controls
32 lines (22 loc) · 858 Bytes
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
from datetime import datetime, timedelta
import csv
#use python 2 to run the code
file= open('input.txt.','r')
fileRead=file.read()
inputArr=fileRead.split('_')
#date array
dateArr=inputArr[0].split(',')
#precipitation array
precipitationArr=inputArr[1].split(',')
#An array to convert and save dates data as timestamps
newDateArr=[]
#conversion function(unix time to utc time)
def unix_to_utc(unix):
return (datetime.fromtimestamp(int(unix)/1000) + timedelta(hours=0)).strftime('%Y-%m-%d %H:%M:%S')
for time in dateArr:
newDateArr.append(unix_to_utc(time))
#saving the result to a csv file
with open ('output.csv','wb') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',',quotechar=' ', quoting=csv.QUOTE_MINIMAL)
for x in range(len(newDateArr)):
filewriter.writerow([newDateArr[x],precipitationArr[x]])