-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathaccount_info.py
78 lines (59 loc) · 1.76 KB
/
account_info.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
78
import logging
import requests
from config import HEADERS, RETRY_TIMES
from tools import logging_wrap
class AccountInfo(object):
def __init__(self, self_uin, g_tk, cookies_value, target_uin=None):
self._self_uin = self_uin
self._g_tk = g_tk
self._target_uin = target_uin or self_uin
self._cookies_pair = {"cookie": cookies_value}
self._blog_num = 0
self._shuoshuo_num = 0
self._photo_num = 0
@property
def self_uin(self):
return self._self_uin
@property
def g_tk(self):
return self._g_tk
@property
def target_uin(self):
return self._target_uin
@property
def blog_num(self):
return self._blog_num
@blog_num.setter
def blog_num(self, num):
if num >= 0:
self._blog_num = num
@property
def shuoshuo_num(self):
return self._shuoshuo_num
@shuoshuo_num.setter
def shuoshuo_num(self, num):
if num >= 0:
self._shuoshuo_num = num
@property
def photo_num(self):
return self._photo_num
@photo_num.setter
def photo_num(self, num):
if num >= 0:
self._photo_num = num
def is_self(self):
return self._self_uin == self._target_uin
@logging_wrap
def get_url(self, url, **kwargs):
r = None
for _ in range(RETRY_TIMES):
r = requests.get(url, headers=HEADERS,
cookies=self._cookies_pair, **kwargs)
if r.ok:
return r
logging.exception("get request failed")
return r
@logging_wrap
def post_url(self, url, **kwargs):
return requests.post(url, headers=HEADERS,
cookies=self._cookies_pair, **kwargs)