Skip to content

Instantly share code, notes, and snippets.

@dundee
Created August 16, 2017 11:21
Show Gist options
  • Save dundee/06a1b4df1c99916b5e7a856f69b4192b to your computer and use it in GitHub Desktop.
Save dundee/06a1b4df1c99916b5e7a856f69b4192b to your computer and use it in GitHub Desktop.
Script for checking if subject is vat payer in CZ
from __future__ import print_function
import requests
from typing import Optional
ADIS_HOST = 'https://adisreg.mfcr.cz'
ADIS_URL = '/cgi-bin/adis/idph/int_dp_prij.cgi?id=1&pocet=1&fu=&OK=+Search+&ZPRAC=RDPHI1&dic='
RESPONSE_VAT_REGISTERED = u'Plátce'
RESPONSE_VAT_INDETIFIED_PERSON = u'Identifikovaná osoba'
def is_vat_payer(vat_number):
# type: (int) -> Optional[bool]
"""
Check if subject with given `vat_number` is vat payer in CZ.
"""
url = ADIS_HOST + ADIS_URL
url = url + vat_number
res = requests.get(
url,
headers={
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Language': 'cs,en-US;q=0.8,en;q=0.6',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
'Host': 'adisreg.mfcr.cz',
'Origin': 'https://adisreg.mfcr.cz',
'Referer': 'http://wwwinfo.mfcr.cz/ares/ares_es.html.cz', # hack: we need to send referer, otherwise ADIS will redirect us
'Upgrade-Insecure-Requests': '1',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache',
},
allow_redirects=False, # we dont want redirects
)
# is identified person, not vat payer
if RESPONSE_VAT_INDETIFIED_PERSON in res.text and RESPONSE_VAT_REGISTERED not in res.text:
return False
# is vat payer, not identified person
if RESPONSE_VAT_INDETIFIED_PERSON not in res.text and RESPONSE_VAT_REGISTERED in res.text:
return True
# is both, we don't know exactly what is currently
return None
if __name__ == '__main__':
import sys
if len(sys.argv) < 2:
print('Usage: {} <vat_number>'.format(sys.argv[0]))
sys.exit(1)
vat_number = sys.argv[1]
is_payer = is_vat_payer(vat_number)
if is_payer:
print('{} is VAT payer'.format(vat_number))
elif is_payer is None:
print('{} is probably VAT payer or VAT identified person'.format(vat_number))
else:
print('{} is not VAT payer'.format(vat_number))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment