-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
65 lines (54 loc) · 1.74 KB
/
server.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 logging
import logging.config
import time
import threading
from datetime import datetime
from datasets import Datasets
from ckan2rdf import CkanMetadata
import json
import os
def task():
global time
logging.info("Executing timer with time:"+str(time))
list_datasets = datasets.getNewDatasets(time)
for dataset in list_datasets:
dataset_id = dataset[0]
dataset_name = dataset[1]
dataset_title = dataset[2]
dataset_descp = dataset[5]
tstamp = dataset[16]
logging.info("ID:"+dataset_id)
logging.info("Timestamp:"+datetime.strftime(tstamp,"%Y-%m-%dT%H:%M:%S.%f"))
# logging.info("TST:"+str(tstamp))
metadata=datasets.getMetadata(dataset[0])
metadata["name"]=dataset_name
metadata["title"]=dataset_title
metadata["notes"]=dataset_descp
logging.info(str(metadata))
ckan_module = CkanMetadata(dataset_name)
result = ckan_module.transformToRdf(metadata)
logging.debug(result)
filerdf = open("files/"+dataset_name+".ttl","w")
filerdf.write(result)
filerdf.close()
logging.info("Generated rdf file:"+dataset_name+".ttl")
time=datetime.strftime(tstamp,"%Y-%m-%dT%H:%M:%S.%fZ")
fileid.seek(0)
# fileid.write(datetime.strftime(time,"%Y-%m-%dT%H:%M:%S"))
fileid.write(time)
logging.info("Waiting for next execution")
threading.Timer(60, task).start()
logging.config.fileConfig('config/logging.cfg') #logfile config
logging.debug("DEBUG MODE")
logging.info("INFO MODE")
time = datetime.utcnow()
pidfile = "timestamp"
fileid = open(pidfile,"r+")
if os.path.exists(pidfile):
time = fileid.read()
logging.info("Get last datasets from "+time)
#time = datetime.datetime.utcnow()
#time = time - datetime.timedelta(days=2)
datasets = Datasets()
ckan_module = CkanMetadata("lens")
task()