-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetting.py
46 lines (35 loc) · 1.27 KB
/
setting.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import json
import urllib3
import requests
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
import configparser
# -----------------------读取微博配置文件--------------------------------
def getWeiboConfig():
with open("weibo.json", "r", encoding="utf-8") as f:
data = json.loads(f.read())
return data
# -----------------------读取邮箱配置文件--------------------------------
def mailConfig():
mail_conf = {}
cf = configparser.ConfigParser()
cf.read("mail.conf")
mail_conf["mail_host"] = cf.get("email", "mail_host")
mail_conf["mail_user"] = cf.get("email", "mail_user")
mail_conf["mail_pass"] = cf.get("email", "mail_pass")
mail_conf["receivers"] = cf.get("email", "receivers").split(",")
return mail_conf
mailConfig()
# -----------------------转换成短链接--------------------------------
def get_short_url(long_url_str):
try:
url = 'http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=' + str(long_url_str)
response = requests.get(
url,
verify=False,
timeout=5
).json()
urlShort = response[0]['url_short']
return urlShort
except Exception as e:
return str(long_url_str)