-
Notifications
You must be signed in to change notification settings - Fork 32
/
functions.py
79 lines (59 loc) · 1.78 KB
/
functions.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#coding=utf-8
import datetime
from urllib import quote
from datetime import datetime
from datetime import timedelta
import json
import time
def today():
time = str(datetime.now())
# print time
date = time.split(" ")[0]
day = date[5:]
# print day
return day
def yesterday():
yest = datetime.now() - timedelta(days=1)
date = str(yest).split(" ")[0]
day = date[5:]
# print day
return day
def days_ago(n):
yest = datetime.now() - timedelta(days=n)
date = str(yest).split(" ")[0]
day = date[5:]
print day
return day
def url_encoding(list):
url_word_list = []
for country in list:
url_word_list.append(quote(country))
return url_word_list
def create_url_list(list):
url_list = []
for country in list:
this_url = "http://m.weibo.cn/container/getIndex?type=wb&queryVal=" + country + \
"&luicode=10000011&lfid=106003type%3D1&title=" + country + \
"&containerid=100103type%3D2%26q%3D" + country + "&page="
url_list.append(this_url)
return url_list
def format_datetime(time):
this_date = time.split(' ')[0]
this_time = time.split(' ')[1]
mon = this_date.split('-')[0]
day = this_date.split('-')[1]
hor = this_time.split(':')[0]
min = this_time.split(':')[1]
return datetime(2017, int(mon), int(day), int(hor), int(min))
def get_this_endtime_text(content):
this_data =json.loads(content)
try:
this_endtime_text = this_data['data']['cards'][0]['card_group'][-1]['mblog']['created_at']
except Exception,e:
raise
return this_endtime_text
def sleep_how_long(lag_hour, starttime, endtime):
during = (endtime - starttime).total_seconds()
lag_seconds = lag_hour * 3600
during = lag_seconds - int(during)
return during