Add search methods
This commit is contained in:
parent
1f1f7bc881
commit
68141fbbf2
25
src/main.py
25
src/main.py
@ -1,25 +1,22 @@
|
||||
from pastebin.client import PastebinClient
|
||||
import time
|
||||
from pastebin.client import PastebinClient, search_by_language
|
||||
|
||||
|
||||
def main():
|
||||
pastebin = PastebinClient()
|
||||
lang_filters = ['Email', 'Python']
|
||||
|
||||
# Fetch public paste list
|
||||
pastebin.update_paste_list()
|
||||
while True:
|
||||
new_pastes = pastebin.update_paste_list()
|
||||
print('Updating pastes...')
|
||||
|
||||
# Fetch full data from a few pastes to test methods
|
||||
pastebin.fetch_paste(0)
|
||||
pastebin.fetch_paste(1)
|
||||
for lang in lang_filters:
|
||||
pastes = search_by_language(new_pastes, lang)
|
||||
|
||||
# Test get_pastes_by_language
|
||||
py_pastes = pastebin.get_pastes_by_language("Python")
|
||||
for paste in py_pastes:
|
||||
print(paste)
|
||||
for paste in pastes:
|
||||
print(f'New {lang} paste: {paste}')
|
||||
|
||||
# Test if duplication is prevented by Paste.__hash__
|
||||
print(len(pastebin.pastes))
|
||||
pastebin.update_paste_list()
|
||||
print(len(pastebin.pastes))
|
||||
time.sleep(60)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -182,3 +182,17 @@ class PastebinClient(PastebinAPI):
|
||||
self.pastes[i] for i, paste in enumerate(self.pastes)
|
||||
if paste.lang.lower() == lang.lower()
|
||||
]
|
||||
|
||||
|
||||
def search_by_language(pastes, lang):
|
||||
return [
|
||||
pastes[i] for i, paste in enumerate(pastes)
|
||||
if paste.lang.lower() == lang.lower()
|
||||
]
|
||||
|
||||
|
||||
def search_by_category(pastes, category):
|
||||
return [
|
||||
pastes[i] for i, paste in enumerate(pastes)
|
||||
if paste.category == category
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user