python工信部投诉电信运营商

默认每天凌晨投诉一遍
貌似工信部投诉改版了,现在用不了了(2019-5-28)

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
167
168
169
#!/usr/bin/env python3
# coding:utf-8
import requests
try:
from urllib.request import quote
except ImportError:
from urllib import quote
import time


def urlencode(str, num=1):
if isinstance(num, int):
if num > 1:
return urlencode(quote(str), num - 1)
elif num == 1:
return quote(str)
raise ValueError('url编码次数错误')
else:
raise ValueError('参数错误')


def submit_complain(uname, address, tel, email, ename, content, result, idnumber, questionid, domain,
postcode='000000'):
"""
工信部电信投诉
:param uname:投诉人姓名
:param address: 投诉人地址
:param tel: 投诉人电话
:param email: 投诉人Email
:param ename: 被投诉人名称,限定
:param content: 投诉内容
:param result: 投诉前被投诉人处理结果
:param idnumber: 身份证号码
:param questionid: 投诉涉及号码
:param domain: 被投诉人地区,限定
:param postcode: 投诉人邮编
:return: 提交结果
"""
qiye_select = {
'其他': '其他.QiYe_9',
'虚拟运营商': '虚拟运营商.QiYe_8',
'中国铁通': '中国铁通.QiYe_5',
'中国联通': '中国联通.QiYe_4',
'中国移动': '中国移动.QiYe_3',
'中国电信': '中国电信.QiYe_1',
}
region_select = {
'工业和信息化部': '0',
'北京市': '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',
}
if (ename not in qiye_select.keys()) or (domain not in region_select):
raise ValueError('企业或地区错误')
base_url = 'http://www.chinatcc.gov.cn:8080/cms/EmailServlet?uname={0}&address={1}&postcode={2}&tel={3}&email={' \
'4}&domain={5}&ename={6}&content={7}&smtsuc={8}&smtfal={9}&idnumber={10}&questionid={11}&work={12} '
headers = {
'HOST': 'www.chinatcc.gov.cn:8080',
'Content-Length': '0',
'Accept': 'application/json, text/javascript, */*',
'Origin': 'http://www.chinatcc.gov.cn:8080',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/63.0.3239.84 Safari/537.36',
'Referer': 'http://www.chinatcc.gov.cn:8080/cms/shensus/',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
'Connection': 'close',
'Content-Type': 'application/x-www-form-urlencoded',
}
smtsuc = r'%25E6%258F%2590%25E4%25BA%25A4%25E6%2588%2590%25E5%258A%259F'
smtfal = r'%25E6%258F%2590%25E4%25BA%25A4%25E5%25A4%25B1%25E8%25B4%25A5'
content = content + r"""
@被申诉企业地址:
@被申诉企业邮政编码:
@被申诉企业联系电话:
@企业处理结果:""" + result
submit_url = base_url.format(
urlencode(uname, 2),
urlencode(address, 2),
postcode,
tel,
urlencode(email, 2),
region_select[domain],
urlencode(qiye_select[ename], 2),
urlencode(content, 2),
smtsuc,
smtfal,
idnumber,
questionid,
'1'
)
return requests.post(submit_url, headers=headers).text


# 姓名
uname = ''
# 投诉人地址
address = ''
# 身份证号码
idnumber = ''
# 投诉问题涉及号码
questionid = ''
# 投诉人电话
tel = ''
# 投诉人Email
email = ''
# 投诉企业名称
ename = ''
# 所属地区
domain = ''
# 投诉内容
content = ''
# 向企业举报,企业处理结果
result = ''
# 每天投诉次数(不能大于24)
number = 1
try:
hour_list = [x for x in range(0, 24, 24//number)]
except ValueError:
exit(0)


def main():
old_time = -1
# 日志
while True:
new_time = int(time.localtime().tm_hour)
if (new_time in hour_list) and (new_time != old_time):
log_txt = str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
tmp = submit_complain(uname, address, tel, email, ename, content,
result, idnumber, questionid, domain)
with open('tousu.log', 'a+') as f:
f.write(log_txt + '\t' + str(tmp).replace('\n', '\t') + '\n')
old_time = new_time
time.sleep(1000)



if __name__ == '__main__':
main()
# python

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×