update_paste_list and get_pastes_by_language return Paste objects
This commit is contained in:
parent
1b0d47c196
commit
1f1f7bc881
@ -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))
|
||||
|
||||
|
||||
|
@ -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()
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user