1234567891011121314151617181920212223242526272829303132333435363738394041 |
- 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)
|