avm99963 | 411e36a | 2020-09-27 23:32:48 +0200 | [diff] [blame] | 1 | import pyodbc |
| 2 | import configparser |
| 3 | from TableParser import TableParser |
| 4 | import datetime |
| 5 | |
| 6 | config = configparser.ConfigParser() |
| 7 | config.read('config.ini') |
| 8 | |
| 9 | db_host = config['db']['host'] |
| 10 | db_database = config['db']['database'] |
| 11 | db_user = config['db']['user'] |
| 12 | db_password = config['db']['password'] |
| 13 | |
| 14 | connection_string = ( |
| 15 | 'DRIVER=MySQL ODBC 8.0 ANSI Driver;' |
| 16 | 'SERVER=' + db_host + ';' |
| 17 | 'DATABASE=' + db_database + ';' |
| 18 | 'UID=' + db_user + ';' |
| 19 | 'PWD=' + db_password + ';' |
| 20 | 'charset=utf8mb4;' |
| 21 | ) |
| 22 | |
| 23 | db = pyodbc.connect(connection_string) |
| 24 | db.setdecoding(pyodbc.SQL_WCHAR, encoding='utf-8') |
| 25 | db.setencoding(encoding='utf-8') |
| 26 | |
| 27 | tomorrow = datetime.date.today() + datetime.timedelta(days=1) |
| 28 | |
| 29 | parser = TableParser('https://fme-intranet.upc.edu/appsext/mrbs/web/day.php') |
| 30 | for area in [2, 6]: |
| 31 | parser.parse(tomorrow.year, tomorrow.month, tomorrow.day, area, db) |