This file contains hidden or 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
self.passed_submissions = read_pickled_set(f"submissions-{username}.pickle") |
This file contains hidden or 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
def _process_submission(self, submission): | |
submission_id = submission.id | |
if submission_id not in self.passed_submissions: | |
... |
This file contains hidden or 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
# store.py | |
import os | |
import pickle | |
from pathlib import Path | |
persistence_dir = Path(os.path.dirname(os.path.abspath(__file__))) | |
def read_pickled_set(filename): | |
path = persistence_dir.joinpath(filename) |
This file contains hidden or 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
submission_reply_list = ["Nice", "up up", "nice job, friend", | |
"I like your creativity", "Very nice"] |
This file contains hidden or 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
def _process_submission(self, submission): | |
comments = submission.comments.list() | |
if len(comments) < 12: | |
submission_reply = random.choice(submission_reply_list) | |
submission.upvote() | |
submission.reply(submission_reply) |
This file contains hidden or 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
def work_on_subreddit(self, subreddit: str, **generator_kwargs): | |
if 'limit' not in generator_kwargs: | |
generator_kwargs['limit'] = 60 | |
submissions = list(self.reddit_client.subreddit(subreddit).new(**generator_kwargs)) | |
for submission in submissions: | |
self._process_submission(submission) |
This file contains hidden or 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
# bot.py | |
import praw | |
class RedditBot: | |
def __init__(self, credentials: dict): | |
self.credentials = credentials | |
username = credentials['username'] | |
self.credentials['user_agent'] = f"testscript by /u/{username}" |
This file contains hidden or 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
[{ | |
"username": "YOUR_USERNAME", | |
"password": "YOUR_PASSWORD", | |
"client_id": "PASTE_CLIENT_ID", | |
"client_secret": "PASTE_CLIENT_SECRET" | |
}] |
This file contains hidden or 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
def process_trade(bot, update, user_data): | |
query = update.callback_query | |
if query.data == CONFIRM: | |
trade = TelegramBot.build_trade(user_data) | |
self._execute_trade(trade) | |
update.callback_query.message.reply_text(f'Scheduled: {trade}') | |
else: | |
show_help(bot, update) |
This file contains hidden or 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
def start_bot(self): | |
self.updater.start_polling() | |
@run_async | |
def _execute_trade(self, trade): | |
loop = asyncio.new_event_loop() | |
task = loop.create_task(self.trade_executor.execute_trade(trade)) | |
loop.run_until_complete(task) | |
@staticmethod |