summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrothedev <grothedev@gmail.com>2022-04-02 15:22:11 -0500
committergrothedev <grothedev@gmail.com>2022-04-02 15:22:11 -0500
commit7517de1aacdcba774be800f5d8d95934da4759aa (patch)
treeed12edac8e156c7513f00b4e34e458e6a4be3a95
parentbd350248819996d31e43418ff881faeb3c223835 (diff)
updates to 4chan query script
-rwxr-xr-x4chan_search/query.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/4chan_search/query.py b/4chan_search/query.py
index f3fc5ce..414bae8 100755
--- a/4chan_search/query.py
+++ b/4chan_search/query.py
@@ -30,20 +30,32 @@ def processCatalog(catalog, b):
results_content.append(catalog[i]['threads'][j]['last_replies'][k]['com'])
#imgs were already retrieved from OP grab
+def repliesSort(catalog):
+ result = []
+ for i in range(0, len(catalog)):
+ for j in range(0, len(catalog[i]['threads'])):
+ url = "https://boards.4channel.org/"+b+"/thread/"+str(catalog[i]['threads'][j]['no'])
+ result.append((url, catalog[i]['threads'][j]['replies']))
+
+ result.sort(key=lambda v: v[1])
+ return result
+
bods = ['a', 'c', 'w', 'm', 'cgl', 'cm', 'f', 'n', 'jp', 'vp', 'v', 'vg', 'vr', 'co', 'g', 'tv', 'k', 'o', 'an', 'tg', 'sp', 'asp', 'sci', 'int', 'out', 'toy', 'biz', 'i', 'po', 'p', 'ck', 'ic', 'wg', 'mu', 'fa', '3', 'gd', 'diy', 'wsg', 's', 'trv', 'fit', 'x', 'lit', 'adv', 'lgbt', 'mlp', 'b', 'r', 'r9k', 'pol', 'soc', 's4s']
abods = ['hc', 'hm', 'h', 'e', 'u', 'd', 'y', 't', 'hr', 'gif']
#####################################################################
+r = True #just for debugging right now
-if len(sys.argv) < 2 or sys.argv[1][0] == '-':
+if not r and (len(sys.argv) < 2 or sys.argv[1][0] == '-'):
print('This program will give you the URLs of all 4chan posts that contain the given search word, either on the entire site or on a select board. You can also use wildcard as search word for all posts of board/site')
print('you must provide a search word, or \"*\" for any word.')
print('Usage: ./query.py <searchword> [board]')
sys.exit(0)
-wod = sys.argv[1] #the search keyword
+if not r:
+ wod = sys.argv[1] #the search keyword
bod = ''
if len(sys.argv) > 2:
bod = sys.argv[2] #the board if interest, if given
@@ -54,12 +66,17 @@ results_img = [] #URLs of all images containing the keyword
if bod == '':
print('searching all boards')
+ repl_res = []
for b in bods:
res = requests.get("https://a.4cdn.org/"+b+"/catalog.json")
- processCatalog(json.loads(res.text), b)
+ repl_res.append(repliesSort(json.loads(res.text)))
+ #processCatalog(json.loads(res.text), b)
+ repl_res.sort(key=lambda v: v[1])
+ print(repl_res)
else:
print('searching board ' + bod)
res = requests.get("https://a.4cdn.org/"+bod+"/catalog.json")
+ print(repliesSort(json.loads(res.text)))
processCatalog(json.loads(res.text), bod)