Last active
August 1, 2019 21:03
-
-
Save Aero-Blue/83d0576c4d21c380733815da4af22db1 to your computer and use it in GitHub Desktop.
Reply script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from requests_html import HTMLSession | |
USERNAME = "" | |
PASSWORD = "" | |
CAPTCHA_CODE = "" | |
class Main: | |
def __init__(self): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-topic", type=int, required=True, dest="topic_id") | |
parser.add_argument("-file", type=str, required=True, dest="file") | |
args = parser.parse_args() | |
assert self.file_exists(args.file) is True, "Couldn't locate specified file" | |
self.session = self.login(USERNAME, PASSWORD, CAPTCHA_CODE) | |
self.post(topic_id, open(args.file).read()) | |
@staticmethod | |
def file_exists(filename): | |
try: | |
open(filename, "r").read() | |
return True | |
except FileNotFoundError: | |
return False | |
@staticmethod | |
def login(username, password, captcha_code): | |
session = HTMLSession() | |
login_uri = "https://bitcointalk.org/index.php?action=login2;ccode={}".format( | |
captcha_code | |
) | |
r = session.post(login_uri, data={"user": username, "passwrd": password}) | |
assert r.status_code is 200 and "logout" in r.text | |
return session | |
def post(self, topic, reply): | |
resp = self.session.get( | |
"https://bitcointalk.org/index.php?action=post;topic={}.0".format(topic) | |
) | |
data = { | |
"topic": resp.html.xpath("//input[@name='topic']/@value"), | |
"subject": resp.html.xpath("//input[@name='subject']/@value"), | |
"message": reply, | |
"sc": resp.html.xpath("//input[@name='sc']/@value"), | |
"seqnum": resp.html.xpath("//input[@name='seqnum']/@value"), | |
} | |
self.session.post( | |
"https://bitcointalk.org/index.php?action=post2;topic={}.0".format(topic), | |
data=data, | |
) | |
return | |
Main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment