diff --git a/src/main.py b/src/main.py index 7980862..3253566 100644 --- a/src/main.py +++ b/src/main.py @@ -5,7 +5,7 @@ def main(): pastebin = PastebinClient() # Fetch public paste list - pastebin.populate_pastes() + pastebin.update_paste_list() # Fetch full data from a few pastes to test methods pastebin.fetch_paste(0) @@ -13,12 +13,12 @@ def main(): # Test get_pastes_by_language py_pastes = pastebin.get_pastes_by_language("Python") - for i in py_pastes: - print(pastebin.pastes[i]) + for paste in py_pastes: + print(paste) # Test if duplication is prevented by Paste.__hash__ print(len(pastebin.pastes)) - pastebin.populate_pastes() + pastebin.update_paste_list() print(len(pastebin.pastes)) diff --git a/src/pastebin/client.py b/src/pastebin/client.py index 46dd1ec..fc5f73b 100644 --- a/src/pastebin/client.py +++ b/src/pastebin/client.py @@ -157,9 +157,14 @@ class PastebinClient(PastebinAPI): super().__init__(headers, proxies, debug) self.pastes = [] - def populate_pastes(self): - pastes_catalog = set(self.get_public_paste_list()) - self.pastes = list(set(self.pastes).union(pastes_catalog)) + def update_paste_list(self): + fetched_pastes = set(self.get_public_paste_list()) + existing_pastes = set(self.pastes) + + new_pastes = fetched_pastes - existing_pastes + self.pastes = list(existing_pastes.union(fetched_pastes)) + + return list(new_pastes) def fetch_paste(self, paste_index): if paste_index >= len(self.pastes): @@ -173,4 +178,7 @@ class PastebinClient(PastebinAPI): return len(self.pastes) def get_pastes_by_language(self, lang): - return [i for i, paste in enumerate(self.pastes) if paste.lang.lower() == lang.lower()] + return [ + self.pastes[i] for i, paste in enumerate(self.pastes) + if paste.lang.lower() == lang.lower() + ]