forked from kercos/ExamplesPythonTelegramBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.py
More file actions
33 lines (29 loc) · 832 Bytes
/
utility.py
File metadata and controls
33 lines (29 loc) · 832 Bytes
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
32
33
# -*- coding: utf-8 -*-
import logging
def import_url_csv(url_csv):
import csv
import requests
import io
r = requests.get(url_csv)
tsv_content = r.content.decode('utf-8')
reader = csv.DictReader(io.StringIO(tsv_content))
return [ row for row in reader ]
def import_url_json(url_json):
import requests
r = requests.get(url_json)
return r.json()
def save_users_vars(users_vars, outputfile):
import json
logging.info("Saving user variables")
with open(outputfile,'w') as f:
json.dump(users_vars, f, sort_keys=True, indent=4)
def load_users_vars(input_file):
import json
logging.info("Loading user variables")
with open(input_file,'r') as f:
try:
vars = json.load(f)
except json.decoder.JSONDecodeError:
logging.warning('input file was currupted, resetting it to empty')
return {}
return vars