mirror of
https://github.com/placeAtlas/atlas.git
synced 2025-01-14 05:14:27 +01:00
Merge branch 'proper-subreddit-format'
This commit is contained in:
commit
1b3532eee2
3 changed files with 1905 additions and 1816 deletions
38
tools/subreddit-format.py
Normal file
38
tools/subreddit-format.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
pattern1 = re.compile(r'"subreddit": "\/r\/(.+?)/?"')
|
||||
pattern2 = re.compile(r'"subreddit": "r\/(.+?)/?"')
|
||||
pattern3 = re.compile(r'"subreddit": "\/?r(?!\/)(.+?)/?"')
|
||||
pattern4 = re.compile(r'"subreddit": "(?:(?:https:\/\/)?www.)?reddit.com\/r\/(.+?)(/[^"]*)*"')
|
||||
pattern5 = re.compile(r'"subreddit": "\[(?:(?:https:\/\/)?www.)?reddit.com\/r\/(.+?)(/[^"]*)*\]\((?:(?:https:\/\/)?www.)?reddit.com\/r\/(.+?)(/[^"]*)*\)"')
|
||||
|
||||
def go(path):
|
||||
|
||||
with open(path, "r+", encoding='UTF-8') as f1:
|
||||
contents = f1.read()
|
||||
|
||||
for match in pattern5.finditer(contents):
|
||||
contents = contents.replace(match.group(0), '"subreddit": "r/' + match.group(2) + '"', 1)
|
||||
|
||||
for match in pattern4.finditer(contents):
|
||||
contents = contents.replace(match.group(0), '"subreddit": "r/' + match.group(1) + '"', 1)
|
||||
|
||||
for match in pattern1.finditer(contents):
|
||||
contents = contents.replace(match.group(0), '"subreddit": "r/' + match.group(1) + '"', 1)
|
||||
|
||||
for match in pattern2.finditer(contents):
|
||||
contents = contents.replace(match.group(0), '"subreddit": "r/' + match.group(1) + '"', 1)
|
||||
|
||||
for match in pattern3.finditer(contents):
|
||||
contents = contents.replace(match.group(0), '"subreddit": "r/' + match.group(1) + '"', 1)
|
||||
|
||||
# # r/... to /r/.. (comment if not needed)
|
||||
for match in pattern2.finditer(contents):
|
||||
contents = contents.replace(match.group(0), '"subreddit": "/r/' + match.group(1) + '"', 1)
|
||||
|
||||
with open(path, "w", encoding='UTF-8') as f2:
|
||||
f2.write(contents)
|
||||
|
||||
go("../web/atlas.json")
|
||||
go("../web/atlas-before-ids-migration.json")
|
File diff suppressed because it is too large
Load diff
2821
web/atlas.json
2821
web/atlas.json
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue