This repository has been archived by the owner on May 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sina.py
166 lines (143 loc) · 5.22 KB
/
sina.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#coding: utf8
from urlfetch import *
import re
from urlparse import parse_qsl, urljoin
import lib
from bot_txt import *
class Sina(object):
def __init__(self, username, password):
self.cookies = None
self.username = username
self.password = password
def login(self):
response = fetch('http://3g.sina.com.cn/prog/wapsite/sso/login_submit.php')
data = response.body
vk = re.search(r'''name="vk"\s+?value="(.*?)"''', data).group(1)
pname = re.search(r'''name="password_(\d+)"''', data).group(1)
post = {
'mobile': self.username,
'password_'+pname: self.password,
'vk': vk,
'remember': 'on',
'submit': '1'
}
response = fetch(
'http://3g.sina.com.cn/prog/wapsite/sso/login_submit.php',
data = post
)
set_cookie = response.msg.getheaders('set-cookie')
self.cookies = setcookielist2cookiestring(set_cookie)
return self.cookies
def del_tweets(self):
while True:
response = fetch(
'http://weibo.cn/dpool/ttt/home.php?cat=1',
headers={'Cookie': self.cookies}
)
data = re.findall(r'href="mblogDeal\.php\?([^"]+?act=del[^"]+)"', response.body)
if not data:
break
for i in data:
j = parse_qsl(i)
qs = dict(j)
qs['act'] = 'dodel'
qs = '&'.join(['='.join(k) for k in qs.items()])
url = 'http://weibo.cn/dpool/ttt/mblogDeal.php?' + qs
try:
fetch(
url,
headers = {'Cookie': self.cookies}
)
print url
except:pass
def unfollow(self):
while True:
response = fetch(
'http://weibo.cn/dpool/ttt/attention.php?cat=0',
headers={'Cookie': self.cookies}
)
data = re.findall(r'href="attnDeal\.php\?([^"]+?act=del[^"]+)"', response.body)
if not data:
break
for i in data:
j = parse_qsl(i)
qs = dict(j)
qs['act'] = 'delc'
qs = '&'.join(['='.join(k) for k in qs.items()])
url = 'http://weibo.cn/dpool/ttt/attnDeal.php?' + qs
try:
fetch(
url,
headers = {'Cookie': self.cookies}
)
print url
except:pass
def remove_followers(self, black=False):
while True:
response = fetch(
'http://weibo.cn/dpool/ttt/attention.php?cat=1',
headers={'Cookie': self.cookies}
)
data = re.findall(r'href="attnDeal\.php\?([^"]+?act=remove[^"]+)"', response.body)
if not data:
break
for i in data:
j = parse_qsl(i)
qs = dict(j)
qs['act'] = 'removec'
qs = '&'.join(['='.join(k) for k in qs.items()])
url = 'http://weibo.cn/dpool/ttt/attnDeal.php?' + qs
try:
fetch(
url,
headers = {'Cookie': self.cookies}
)
print url
except:pass
def direct_messages(self):
response = fetch(
'http://weibo.cn/msg/',
headers={'Cookie': self.cookies}
)
def parse_response(data):
data = txt_wrap_by_all('<div class="c">', '</div>', data)
for i in data:
if i.startswith('<span class="kt">[新]</span>'):
i = i[len('<span class="kt">[新]</span>'):]
msg = txt_wrap_by('</span>', '<span', i)
uid = txt_wrap_by('/msg/chat/send?uid=', '&', i)
if msg and uid:
msg = lib.strip_tags(msg)
msg = msg.replace(' ', '')
yield (uid, msg)
return list(parse_response(response.body))
def del_direct_message(self, uid):
response = fetch(
'http://weibo.cn/msg/chat/del/%s?&do=del&&rl=0' % uid,
headers={'Cookie': self.cookies}
)
return response
def update_q(self, qid, status):
response = fetch(
'http://weibo.cn/dpool/ttt/grouphome.php',
headers={
'Cookie': self.cookies,
},
data = {
'act': 'addmblog',
'groupid': qid,
'from': 'home',
'rl': 0,
'content': status
},
)
return response
if __name__ == '__main__':
import sys
username, password = sys.argv[1:]
sina = Sina(username, password)
sina.login()
#sina.direct_messages()
#sina.del_tweets()
#sina.unfollow()
#sina.remove_followers()