File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ """Build a map of url => id from all completed post JSON files."""
3+
4+ import json
5+ import glob
6+ import os
7+
8+ def build_url_map ():
9+ completed_dir = os .path .join (os .path .dirname (__file__ ), 'completed' )
10+ url_map = {}
11+
12+ for filepath in sorted (glob .glob (os .path .join (completed_dir , '*.json' ))):
13+ with open (filepath ) as f :
14+ data = json .load (f )
15+ url = data .get ('url' )
16+ post_id = data .get ('id' )
17+ if url and post_id :
18+ url_map [url ] = post_id
19+
20+ return url_map
21+
22+ if __name__ == '__main__' :
23+ url_map = build_url_map ()
24+ # print(json.dumps(url_map, indent=2))
25+ print (f"\n Total: { len (url_map )} entries" , file = __import__ ('sys' ).stderr )
26+
27+ for url , post_id in url_map .items ():
28+ # if post_id is not a number
29+ if not isinstance (post_id , int ):
30+ print (f"UPDATE post set ref_id = '{ post_id } ', ref_urn = 'urn:reddit:post:{ post_id } ' where url = '{ url } ';" )
You can’t perform that action at this time.
0 commit comments