Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import io
- import zipfile
- import csv
- import re
- import os
- def postalRequest():
- codes=[]
- print("Please enter first ZIP code for the compartment ")
- codes.append(input())
- print("Please enter second ZIP code for the compartment")
- codes.append(input())
- return codes
- url1 = 'http://www.kody-pocztowe.dokladnie.com/kody.csv.zip'
- r = requests.get(url1)
- f = open ('dll.zip', 'wb')
- f.write(r.content)
- f.close()
- os.mkdir('targetdir')
- with zipfile.ZipFile('dll.zip','r') as zip_ref:
- zip_ref.extractall('targetdir')
- pattern = re.compile(r'(\d\d)[-](\d\d\d)')
- zipInterval=postalRequest()
- csv_file= open('targetdir\\kody.csv', 'r', encoding='utf-8')
- csv_reader = csv.reader(csv_file)
- for line in csv_reader:
- matches=pattern.finditer(''.join(line))
- for match in matches:
- if match.group(0)>=min(zipInterval) and match.group(0)<=max(zipInterval):
- print(match.group(0))
- print(line)
Advertisement
Add Comment
Please, Sign In to add comment