Allow setting a config file from the command line
This commit is contained in:
@ -4,14 +4,16 @@ A simple script that sends the daily weather to a FreeMobile phone
|
||||
"""
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import pyowm
|
||||
import requests
|
||||
import sys
|
||||
|
||||
class WeatherToFreemobile():
|
||||
def __init__(self, config_file='config.json'):
|
||||
logging.info('Load configuration from config.json file')
|
||||
with open('config.json') as config_file:
|
||||
self.config = json.load(config_file)
|
||||
def __init__(self, config_file):
|
||||
logging.info('Load configuration from {}'.format(config_file))
|
||||
with open(config_file) as configuration:
|
||||
self.config = json.load(configuration)
|
||||
|
||||
def send_sms_to_freemobile(self, message):
|
||||
"""
|
||||
@ -60,5 +62,12 @@ class WeatherToFreemobile():
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %(levelname)s - %(message)s')
|
||||
wtf = WeatherToFreemobile()
|
||||
if len(sys.argv) > 1:
|
||||
wtf = WeatherToFreemobile(sys.argv[1])
|
||||
else:
|
||||
config_file = os.path.join(
|
||||
os.path.dirname(os.path.realpath(sys.argv[0])),
|
||||
'config.json'
|
||||
)
|
||||
wtf = WeatherToFreemobile(config_file)
|
||||
wtf.send_sms_to_freemobile(wtf.get_weather())
|
||||
|
Reference in New Issue
Block a user