41 lines
935 B
Python
41 lines
935 B
Python
import gsm
|
|
import logging
|
|
import requests
|
|
import json
|
|
|
|
def load_config():
|
|
with open('config/gsm.json') as config:
|
|
gsm = json.load(config)
|
|
|
|
with open('config/api.json') as config:
|
|
api = json.load(config)
|
|
|
|
config = {
|
|
"gsm": gsm,
|
|
"api": api
|
|
}
|
|
return config
|
|
|
|
config = load_config()
|
|
|
|
gsm_modules = list()
|
|
for module in config["gsm"]:
|
|
print(module)
|
|
gsm_object = gsm.Gsm(module["port"], module["msisdn"])
|
|
gsm_modules.append(gsm_object)
|
|
|
|
messages_queue = list()
|
|
while True:
|
|
for gsm_object in gsm_modules:
|
|
messages = gsm_object.fetch_messages()
|
|
if messages:
|
|
messages_queue.extend(messages)
|
|
messages = None
|
|
|
|
for message in messages_queue:
|
|
try:
|
|
r = requests.put(config["api"]["url"], headers={"key": config["api"]["key"]}, data=json.dumps(message), timeout=10)
|
|
except:
|
|
logging.error("Failed pushing messages queue to frontend")
|
|
if r:
|
|
messages_queue.delete(message) |