This repository has been archived by the owner on Sep 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
nntp.py
executable file
·267 lines (230 loc) · 6.74 KB
/
nntp.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
############################LICENCE###################################
# Copyright (c) 2016 Faissal Bensefia
# This file is part of Yukko.
#
# Yukko is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Yukko is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Yukko. If not, see <http://www.gnu.org/licenses/>.
#######################################################################
import requests
import json
import datetime
import os
captchaID = ""
nodeList = []
node=""
proxy={
"http":"",
"https":""
}
header={
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Firefox/45.0"
}
# Reads nodes from a text file
def readNodes(nodeFile):
global nodeList
with open(nodeFile, 'r') as file:
nodeList=[i.strip() for i in file]
# Picks a random new node
def cycleNode():
global node
global nodeList
node = nodeList[int.from_bytes(os.urandom(4), "big") % len(nodeList)]
readNodes("nodeList.txt")
cycleNode()
class file():
def __init__(self, jason):
global node
self.url = node + "img/" + jason["Path"]
self.fileName = jason["Name"]
def download(self, downloadDir=""):
global proxy
r = requests.get(self.url, proxies=proxy)
with open(downloadDir + self.fileName, "wb") as f:
for i in r:
f.write(i)
return r.status_code
class post():
def __init__(self, jason, isOP=False):
self.isOP = isOP
self.name = jason["PostName"]
self.subject = jason["PostSubject"]
self.ID = jason["Message_id"]
self.hash = jason["HashLong"]
self.timestamp = datetime.datetime.fromtimestamp(jason["Posted"])
self.text = jason["PostMessage"]
self.files = []
if jason["Files"] != None:
self.files=[file(i) for i in jason["Files"]]
class thread():
def __init__(self, jason, parentBoard):
self.parentBoard = parentBoard
self.posts = []
self.posts.append(post(jason[0], True))
self.posts.extend([post(i) for i in jason[1:]])
def __len__(self):
return len(self.posts)
def __iter__(self):
self.iteratorIndex = 0
return self
def __next__(self):
if self.iteratorIndex >= len(self):
raise StopIteration
else:
toRet = self[self.iteratorIndex]
self.iteratorIndex += 1
return toRet
def __getitem__(self, key):
return self.posts[key]
def refresh(self):
global proxy
global headers
r = requests.get(node + "t/" + str(self[0].hash) + "/json", proxies=proxy,headers=header)
self.status = r.status_code
self.posts = []
if self.status >= 200 and self.status < 300:
jason = r.json()
if jason: # Only do this if None wasn't returned
self.posts = []
self.posts.append(post(jason[0], True))
self.posts.extend([post(i) for i in jason[1:]])
def overview(self, postCount):
# Returns the first and last postCount posts
if len(self.posts) > 1:
postOverview = self.posts[max(1, len(self.posts) - postCount):]
else:
postOverview = []
postOverview.insert(0, self.posts[0])
return postOverview
def post(self, name, sub, msg, captcha, *files):
global proxy
global node
global captchaID
global header
filesToUpload = [("", "")]
# Ability to use same key for multiple files
filesToUpload.extend([("attachment_uploaded", open(i, "rb")) for i in files])
postArgs = {
"reference": self.posts[0].ID,
"name": name,
"subject": sub,
"message": msg,
"captcha": captcha,
"captcha_id": captchaID,
"pow": ""
}
r = requests.post(node + "post/" + self.parentBoard.boardname,
files=filesToUpload, data=postArgs, headers=header, proxies=proxy)
return r.status_code
class board():
def __init__(self, boardname, page):
global node
global proxy
global header
cycleNode()
r = requests.get(node +"b/"+ boardname + "/" + str(page) + "/json", proxies=proxy,headers=header)
self.status = r.status_code
self.page = page
self.boardname = boardname
self.threadOverviews = []
if self.status >= 200 and self.status < 300:
jason = r.json()
if jason: # Only do this if None wasn't returned
self.threadOverviews.extend([thread(i, self) for i in jason["posts"]])
def refresh(self):
global node
global proxy
global header
cycleNode()
r = requests.get(node +"b/"+ self.boardname + "/" + str(self.page) + "/json", proxies=proxy,headers=header)
self.status = r.status_code
self.threadOverviews = []
if self.status >= 200 and self.status < 300:
jason = r.json()
if jason: # Only do this if None wasn't returned
self.threadOverviews.extend([thread(i, self) for i in jason["posts"]])
def __iter__(self):
self.iteratorIndex = 0
return self
def __next__(self):
if self.iteratorIndex >= len(self):
raise StopIteration
else:
toRet = self[self.iteratorIndex]
self.iteratorIndex += 1
return toRet
def __len__(self):
return len(self.threadOverviews)
def __getitem__(self, key):
return self.threadOverviews[key]
def post(self, name, sub, msg, captcha, *files):
global proxy
global node
global captchaID
global header
filesToUpload = [("", "")]
# Ability to use same key for multiple files
for i in files:
filesToUpload.append(("attachment_uploaded", open(i, "rb")))
postArgs = {
"reference": "",
"name": name,
"subject": sub,
"message": msg,
"captcha": captcha,
"captcha_id": captchaID,
"pow": ""
}
r = requests.post(node + "post/" + self.boardname,
files=filesToUpload, data=postArgs, headers=header, proxies=proxy)
return r.status_code
def cleanupCaptcha():
global captchaID
try:
# Get rid of the last CAPTCHA so we don't fill /tmp/ with crap
os.remove("/tmp/" + captchaID + ".png")
except:
pass
def getCaptcha():
global captchaID
global proxy
cleanupCaptcha()
r = requests.get(node + "captcha/img", proxies=proxy,headers=header)
captchaID = r.url[len(node + "captcha/"):-4]
# Download the file
with open("/tmp/" + captchaID + ".png", "wb") as f:
for i in r:
f.write(i)
return "/tmp/" + captchaID + ".png"
class boardList():
def __init__(self):
global proxy
global header
cycleNode()
r = requests.get(node + "boards.json", proxies=proxy,headers=header)
self.boards = r.json()
def __getitem__(self, key):
return self.boards[key]
def __iter__(self):
self.iteratorIndex = 0
return self
def __next__(self):
if self.iteratorIndex >= len(self):
raise StopIteration
else:
toRet = self[self.iteratorIndex]
self.iteratorIndex += 1
return toRet
def __len__(self):
return len(self.boards)