Fix some formatting

This commit is contained in:
Serene-Arc
2021-04-12 16:53:01 +10:00
committed by Ali Parlakci
parent aa8032e95f
commit af95f3ff66

View File

@@ -101,7 +101,8 @@ class RedditDownloader:
oauth2_authenticator = OAuth2Authenticator( oauth2_authenticator = OAuth2Authenticator(
scopes, scopes,
self.cfg_parser.get('DEFAULT', 'client_id'), self.cfg_parser.get('DEFAULT', 'client_id'),
self.cfg_parser.get('DEFAULT', 'client_secret')) self.cfg_parser.get('DEFAULT', 'client_secret'),
)
token = oauth2_authenticator.retrieve_new_token() token = oauth2_authenticator.retrieve_new_token()
self.cfg_parser['DEFAULT']['user_token'] = token self.cfg_parser['DEFAULT']['user_token'] = token
with open(self.config_location, 'w') as file: with open(self.config_location, 'w') as file:
@@ -109,16 +110,20 @@ class RedditDownloader:
token_manager = OAuth2TokenManager(self.cfg_parser, self.config_location) token_manager = OAuth2TokenManager(self.cfg_parser, self.config_location)
self.authenticated = True self.authenticated = True
self.reddit_instance = praw.Reddit(client_id=self.cfg_parser.get('DEFAULT', 'client_id'), self.reddit_instance = praw.Reddit(
client_secret=self.cfg_parser.get('DEFAULT', 'client_secret'), client_id=self.cfg_parser.get('DEFAULT', 'client_id'),
user_agent=socket.gethostname(), client_secret=self.cfg_parser.get('DEFAULT', 'client_secret'),
token_manager=token_manager) user_agent=socket.gethostname(),
token_manager=token_manager,
)
else: else:
logger.debug('Using unauthenticated Reddit instance') logger.debug('Using unauthenticated Reddit instance')
self.authenticated = False self.authenticated = False
self.reddit_instance = praw.Reddit(client_id=self.cfg_parser.get('DEFAULT', 'client_id'), self.reddit_instance = praw.Reddit(
client_secret=self.cfg_parser.get('DEFAULT', 'client_secret'), client_id=self.cfg_parser.get('DEFAULT', 'client_id'),
user_agent=socket.gethostname()) client_secret=self.cfg_parser.get('DEFAULT', 'client_secret'),
user_agent=socket.gethostname(),
)
def _retrieve_reddit_lists(self) -> list[praw.models.ListingGenerator]: def _retrieve_reddit_lists(self) -> list[praw.models.ListingGenerator]:
master_list = [] master_list = []
@@ -146,11 +151,12 @@ class RedditDownloader:
self.cfg_parser.read(cfg_path) self.cfg_parser.read(cfg_path)
self.config_location = cfg_path self.config_location = cfg_path
return return
possible_paths = [Path('./config.cfg'), possible_paths = [
Path('./default_config.cfg'), Path('./config.cfg'),
Path(self.config_directory, 'config.cfg'), Path('./default_config.cfg'),
Path(self.config_directory, 'default_config.cfg'), Path(self.config_directory, 'config.cfg'),
] Path(self.config_directory, 'default_config.cfg'),
]
self.config_location = None self.config_location = None
for path in possible_paths: for path in possible_paths:
if path.resolve().expanduser().exists(): if path.resolve().expanduser().exists():
@@ -210,7 +216,8 @@ class RedditDownloader:
reddit.search( reddit.search(
self.args.search, self.args.search,
sort=self.sort_filter.name.lower(), sort=self.sort_filter.name.lower(),
limit=self.args.limit)) limit=self.args.limit,
))
logger.debug( logger.debug(
f'Added submissions from subreddit {reddit} with the search term "{self.args.search}"') f'Added submissions from subreddit {reddit} with the search term "{self.args.search}"')
else: else:
@@ -280,7 +287,9 @@ class RedditDownloader:
logger.debug(f'Retrieving submitted posts of user {self.args.user}') logger.debug(f'Retrieving submitted posts of user {self.args.user}')
generators.append( generators.append(
sort_function( sort_function(
self.reddit_instance.redditor(self.args.user).submissions, limit=self.args.limit)) self.reddit_instance.redditor(self.args.user).submissions,
limit=self.args.limit,
))
if not self.authenticated and any((self.args.upvoted, self.args.saved)): if not self.authenticated and any((self.args.upvoted, self.args.saved)):
logger.warning('Accessing user lists requires authentication') logger.warning('Accessing user lists requires authentication')
else: else: