Browse Source

Refactored a couple regular expressions

Clara Hobbs 8 years ago
parent
commit
57f58295a4
1 changed files with 6 additions and 4 deletions
  1. 6
    4
      languageupdater.py

+ 6
- 4
languageupdater.py View File

@@ -55,13 +55,15 @@ class LanguageUpdater:
55 55
         r = requests.post(url, files=files, data=values)
56 56
 
57 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 60
         for line in r.text.split('\n'):
59 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 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 67
                 break
66 68
 
67 69
         lm_url = path + '/' + number + '.lm'

Loading…
Cancel
Save