1919import json
2020import codecs
2121import re
22+ import sys
2223from urllib .parse import urlparse , parse_qs
2324
2425S = ';'
2526
2627MOD_SEPARATOR = ','
2728
2829CURSEFORGE_PATTERN1 = re .compile (
29- r'^/minecraft/(mc-mods|customization|mc-addons|customization/configuration)/(?P<modid>[\w-]+)(/(.*?))?$' )
30+ r'^/minecraft/(mc-mods|customization|mc-addons|customization/configuration)/+ (?P<modid>[\w-]+)(/(.*?))?$' )
3031CURSEFORGE_PATTERN2 = re .compile (
3132 r'^/projects/(?P<modid>[\w-]+)(/(.*?))?$' )
3233CURSEFORGE_PATTERN3 = re .compile (
3334 r'^/mc-mods/minecraft/(?P<modid>[\w-]+)(/(.*?))?$' )
35+ CURSEFORGE_PATTERN4 = re .compile (
36+ r'^/legacy/mc-mods/minecraft/(\d+)-(?P<modid>[\w-]+)'
37+ )
3438
3539
3640def parseCurseforge (url ):
3741 res = urlparse (url )
3842 if res .scheme not in ['http' , 'https' ]:
3943 return ''
40- for pattern in [CURSEFORGE_PATTERN1 , CURSEFORGE_PATTERN2 , CURSEFORGE_PATTERN3 ]:
44+ for pattern in [CURSEFORGE_PATTERN1 , CURSEFORGE_PATTERN2 , CURSEFORGE_PATTERN3 , CURSEFORGE_PATTERN4 ]:
4145 match = pattern .match (res .path )
4246 if match :
4347 return match .group ('modid' )
@@ -55,7 +59,7 @@ def parseMcmod(url):
5559 return ''
5660
5761
58- MCBBS_HTML_PATTERN = re .compile (r'/thread-(?P<modid>\d+)-(\d+)-(\d+).html' )
62+ MCBBS_HTML_PATTERN = re .compile (r'/+ thread-(?P<modid>\d+)-(\d+)-(\d+).html' )
5963MCBBS_PHP_PATTERN = re .compile (r'' )
6064
6165
@@ -78,15 +82,26 @@ def parseMcbbs(url):
7882 return ''
7983
8084
85+ skip = [
86+ 'Minecraft' ,
87+ 'The Building Game'
88+ ]
89+
90+
8191if __name__ == '__main__' :
82- with codecs .open ('data.json' , mode = 'r' , encoding = 'utf-8-sig' ) as jsonfile , codecs .open ('data.csv' , mode = 'w' , encoding = 'utf-8' ) as outfile :
92+ json_name = sys .argv [1 ] or 'data.json'
93+
94+ with codecs .open (json_name , mode = 'r' , encoding = 'utf-8-sig' ) as jsonfile , codecs .open ('data.csv' , mode = 'w' , encoding = 'utf-8' ) as outfile :
8395 data = json .load (jsonfile )
8496
8597 for mod in data :
8698 chinese_name = mod ['name' ]['main' ]
8799 sub_name = mod ['name' ]['sub' ]
88100 abbr = mod ['name' ]['abbr' ]
89101
102+ if sub_name in skip :
103+ continue
104+
90105 if S in chinese_name :
91106 print ('Error! ' + chinese_name )
92107 exit (1 )
0 commit comments