Bläddra i källkod

Refactored a couple regular expressions

Clara Hobbs 8 år sedan
förälder
incheckning
57f58295a4
1 ändrade filer med 6 tillägg och 4 borttagningar
  1. 6
    4
      languageupdater.py

+ 6
- 4
languageupdater.py Visa fil

55
         r = requests.post(url, files=files, data=values)
55
         r = requests.post(url, files=files, data=values)
56
 
56
 
57
         # Parse response to get URLs of the files we need
57
         # Parse response to get URLs of the files we need
58
+        path_re = r'.*<title>Index of (.*?)</title>.*'
59
+        number_re = r'.*TAR[0-9]*?\.tgz.*'
58
         for line in r.text.split('\n'):
60
         for line in r.text.split('\n'):
59
             # If we found the directory, keep it and don't break
61
             # If we found the directory, keep it and don't break
60
-            if re.search(r'.*<title>Index of (.*?)</title>.*', line):
61
-                path = host + re.sub(r'.*<title>Index of (.*?)</title>.*', r'\1', line)
62
+            if re.search(path_re, line):
63
+                path = host + re.sub(path_re, r'\1', line)
62
             # If we found the number, keep it and break
64
             # If we found the number, keep it and break
63
-            elif re.search(r'.*TAR[0-9]*?\.tgz.*', line):
64
-                number = re.sub(r'.*TAR([0-9]*?)\.tgz.*', r'\1', line)
65
+            elif re.search(number_re, line):
66
+                number = re.sub(number_re, r'\1', line)
65
                 break
67
                 break
66
 
68
 
67
         lm_url = path + '/' + number + '.lm'
69
         lm_url = path + '/' + number + '.lm'

Laddar…
Avbryt
Spara