-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeteoRetrieverDaemon.py
More file actions
32 lines (27 loc) · 1.09 KB
/
MeteoRetrieverDaemon.py
File metadata and controls
32 lines (27 loc) · 1.09 KB
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
import sys
import signal
import time
import daemon
import MeteoFranceInterface.MeteoFranceInterface
import RedisHandler.RedisHandler
def shutdown(signum, frame): # signum and frame are mandatory
print("MeteoRetrieverDaemon - EXITING NOW")
sys.exit(0)
def get_meteo():
global conn
while True:
print("MeteoRetrieverDaemon - Retrieving Meteo France data - "+time.strftime("%d/%m/%Y %H:%M:%S"))
try:
redisCnxStatus,conn = RedisHandler.RedisHandler.handleRedisCnx(conn)
aCityCode = MeteoFranceInterface.MeteoFranceInterface.getCityCodeFromName("biot")
city, extractionTime, resultDict = MeteoFranceInterface.MeteoFranceInterface.getDataFromMeteoFranceAPI2( aCityCode )
conn.hmset(city+'-'+extractionTime,resultDict)
except Exception as exception:
print("...Exception caught")
time.sleep(600)
conn = None
with daemon.DaemonContext(detach_process=False,stdout=sys.stdout,stderr=sys.stderr, signal_map={
signal.SIGTERM: shutdown,
signal.SIGTSTP: shutdown
}):
get_meteo()