Guest User

Untitled

a guest
May 3rd, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import requests
  2. import io
  3. import zipfile
  4. import csv
  5. import re
  6. import os
  7.  
  8. def postalRequest():
  9. codes=[]
  10. print("Please enter first ZIP code for the compartment ")
  11. codes.append(input())
  12.  
  13. print("Please enter second ZIP code for the compartment")
  14. codes.append(input())
  15. return codes
  16.  
  17.  
  18.  
  19. url1 = 'http://www.kody-pocztowe.dokladnie.com/kody.csv.zip'
  20.  
  21.  
  22.  
  23. r = requests.get(url1)
  24.  
  25. f = open ('dll.zip', 'wb')
  26. f.write(r.content)
  27. f.close()
  28. os.mkdir('targetdir')
  29. with zipfile.ZipFile('dll.zip','r') as zip_ref:
  30. zip_ref.extractall('targetdir')
  31.  
  32.  
  33. pattern = re.compile(r'(\d\d)[-](\d\d\d)')
  34.  
  35. zipInterval=postalRequest()
  36.  
  37.  
  38. csv_file= open('targetdir\\kody.csv', 'r', encoding='utf-8')
  39. csv_reader = csv.reader(csv_file)
  40. for line in csv_reader:
  41. matches=pattern.finditer(''.join(line))
  42. for match in matches:
  43. if match.group(0)>=min(zipInterval) and match.group(0)<=max(zipInterval):
  44. print(match.group(0))
  45. print(line)
Advertisement
Add Comment
Please, Sign In to add comment