def __init__(self): super().__init__(self) with open(join(TEST_DATA_DIR, 'common_pairs.xml'), 'rb') as infile: t_pairs = new_xml(infile.read()).find('pairs') t_pair_s = t_pairs.find_all('pair') for t_pair in t_pair_s: request = Request.from_xml(t_pair.request) response = Response.from_xml(t_pair.response) self[request] = response
def xmllist(request): LOGGER.debug('XML list accessed', request, request.GET) reqd = request.GET.copy() try: par = g2p(reqd) res = Vec.objects.filter(**par).order_by('firstAction', 'rocnik', 'bc', 'idOsobyPuvodce').distinct() except: raise Http404 total = res.count() if total > EXLIM: return render( request, 'exlim.xhtml', { 'app': APP, 'page_title': EXLIM_TITLE, 'limit': EXLIM, 'total': total, 'back': reverse('pir:mainpage') }) dec = { 'insolvencies': { 'xmlns': 'http://' + LOCAL_SUBDOMAIN, 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': 'http://{} {}/static/{}-{}.xsd'.format(LOCAL_SUBDOMAIN, LOCAL_URL, APP, APPVERSION), 'application': APP, 'version': APPVERSION, 'created': datetime.now().replace(microsecond=0).isoformat() } } xml = new_xml('') tag_insolvencies = xml_decorate(xml.new_tag('insolvencies'), dec) xml.append(tag_insolvencies) for item in res: tag_insolvency = xml.new_tag('insolvency') tag_insolvencies.append(tag_insolvency) tag_court = xml.new_tag('court') tag_insolvency.append(tag_court) tag_court['id'] = item.idOsobyPuvodce tag_court.append(L2N[item.idOsobyPuvodce]) tag_ref = xml.new_tag('ref') tag_insolvency.append(tag_ref) tag_court = xml.new_tag('court') tag_court.append(L2S[item.idOsobyPuvodce]) tag_ref.append(tag_court) tag_senate = xml.new_tag('senate') tag_senate.append(str(item.senat)) tag_ref.append(tag_senate) tag_register = xml.new_tag('register') tag_register.append('INS') tag_ref.append(tag_register) tag_number = xml.new_tag('number') tag_number.append(str(item.bc)) tag_ref.append(tag_number) tag_year = xml.new_tag('year') tag_year.append(str(item.rocnik)) tag_ref.append(tag_year) if item.druhStavRizeni: tag_state = xml.new_tag('state') tag_state.append(S2D[item.druhStavRizeni.desc]) tag_insolvency.append(tag_state) tag_debtors = xml.new_tag('debtors') tag_insolvency.append(tag_debtors) xml_addparties(getosoby(item, 'debtor'), xml, tag_debtors, 'debtor') tag_trustees = xml.new_tag('trustees') tag_insolvency.append(tag_trustees) xml_addparties(getosoby(item, 'trustee'), xml, tag_trustees, 'trustee') if 'creditors' in reqd: tag_creditors = xml.new_tag('creditors') tag_insolvency.append(tag_creditors) xml_addparties(getosoby(item, 'motioner', 'creditor'), xml, tag_creditors, 'creditor') response = HttpResponse(str(xml).encode('utf-8') + b'\n', content_type='text/xml; charset=utf-8') response['Content-Disposition'] = 'attachment; filename=Insolvence.xml' return response
def xmllist(request): LOGGER.debug('XML list accessed', request, request.GET) reqd = request.GET.copy() try: par = g2p(reqd) res = Hearing.objects.filter(**par).order_by('time', 'pk').distinct() except: raise Http404 total = res.count() if total > EXLIM: return render( request, 'exlim.xhtml', {'app': APP, 'page_title': EXLIM_TITLE, 'limit': EXLIM, 'total': total, 'back': reverse('psj:mainpage')}) dec = { 'hearings': { 'xmlns': 'http://' + LOCAL_SUBDOMAIN, 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': 'http://{} {}/static/{}-{}.xsd' .format(LOCAL_SUBDOMAIN, LOCAL_URL, APP, APPVERSION), 'application': APP, 'version': APPVERSION, 'created': datetime.now().replace(microsecond=0).isoformat() } } xml = new_xml('') tag_hearings = xml_decorate(xml.new_tag('hearings'), dec) xml.append(tag_hearings) for item in res: tag_hearing = xml.new_tag('hearing') tag_hearings.append(tag_hearing) tag_court = xml.new_tag('court') tag_hearing.append(tag_court) tag_court['id'] = item.courtroom.court_id tag_court.append(item.courtroom.court.name) tag_courtroom = xml.new_tag('courtroom') tag_hearing.append(tag_courtroom) tag_courtroom.append(item.courtroom.desc) tag_time = xml.new_tag('time') tag_hearing.append(tag_time) tag_time.append(item.time.replace(microsecond=0).isoformat()) tag_ref = xml.new_tag('ref') tag_hearing.append(tag_ref) tag_senate = xml.new_tag('senate') tag_senate.append(str(item.senate)) tag_ref.append(tag_senate) tag_register = xml.new_tag('register') tag_register.append(item.register) tag_ref.append(tag_register) tag_number = xml.new_tag('number') tag_number.append(str(item.number)) tag_ref.append(tag_number) tag_year = xml.new_tag('year') tag_year.append(str(item.year)) tag_ref.append(tag_year) tag_judge = xml.new_tag('judge') tag_hearing.append(tag_judge) tag_judge.append(item.judge.name) tag_parties = xml.new_tag('parties') tag_hearing.append(tag_parties) for party in item.parties.values(): tag_party = xml.new_tag('party') tag_parties.append(tag_party) tag_party.append(party['name']) tag_form = xml.new_tag('form') tag_hearing.append(tag_form) tag_form.append(item.form.name) tag_closed = xml.new_tag('closed') tag_hearing.append(tag_closed) tag_closed.append(xmlbool(item.closed)) tag_cancelled = xml.new_tag('cancelled') tag_hearing.append(tag_cancelled) tag_cancelled.append(xmlbool(item.cancelled)) response = HttpResponse( str(xml).encode('utf-8') + b'\n', content_type='text/xml; charset=utf-8') response['Content-Disposition'] = 'attachment; filename=Jednani.xml' return response
def xmllist(request): LOGGER.debug('XML list accessed', request, request.GET) reqd = request.GET.copy() try: par = g2p(reqd) resins = DocumentIndex.objects.using('sphinx').filter(**par).order_by( 'posted', 'id') except: raise Http404 total = resins.count() if total > EXLIM: return render( request, 'exlim.xhtml', { 'app': APP, 'page_title': EXLIM_TITLE, 'limit': EXLIM, 'total': total, 'back': reverse('uds:mainpage') }) resins = list(resins.values_list('id', flat=True)) res = Document.objects.filter(id__in=resins).order_by('posted', 'id').distinct() doc = { 'documents': { 'xmlns': 'http://' + LOCAL_SUBDOMAIN, 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': 'http://{} {}/static/{}-{}.xsd'.format(LOCAL_SUBDOMAIN, LOCAL_URL, APP, APPVERSION), 'application': APP, 'version': APPVERSION, 'created': datetime.now().replace(microsecond=0).isoformat() } } xml = new_xml('') tag_documents = xml_decorate(xml.new_tag('documents'), doc) xml.append(tag_documents) for item in res: tag_document = xml.new_tag('document') tag_documents.append(tag_document) tag_document['id'] = item.docid tag_publisher = xml.new_tag('publisher') tag_document.append(tag_publisher) tag_publisher['id'] = item.publisher.pubid tag_publisher.append(item.publisher.name) tag_ref = xml.new_tag('ref') tag_document.append(tag_ref) tag_ref.append(item.ref) tag_description = xml.new_tag('description') tag_document.append(tag_description) tag_description.append(item.desc) tag_agenda = xml.new_tag('agenda') tag_document.append(tag_agenda) tag_agenda.append(item.agenda.desc) tag_posted = xml.new_tag('posted') tag_document.append(tag_posted) tag_posted.append(item.posted.isoformat()) tag_files = xml.new_tag('files') tag_document.append(tag_files) for fil in File.objects.filter( document=item).order_by('fileid').distinct(): tag_file = xml.new_tag('file') tag_files.append(tag_file) tag_file['id'] = fil.fileid tag_name = xml.new_tag('name') tag_file.append(tag_name) tag_name.append(fil.name) tag_url = xml.new_tag('url') tag_file.append(tag_url) tag_url.append(join(REPO_PREFIX, str(fil.fileid), fil.name)) response = HttpResponse(str(xml).encode('utf-8') + b'\n', content_type='text/xml; charset=utf-8') response['Content-Disposition'] = 'attachment; filename=Dokumenty.xml' return response
def to_xml(debt): dec = { 'debt': { 'xmlns': 'http://' + LOCAL_SUBDOMAIN, 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': 'http://{} {}/static/{}-{}.xsd'.format(LOCAL_SUBDOMAIN, LOCAL_URL, APP, APPVERSION), 'application': APP, 'version': APPVERSION, 'created': datetime.now().replace(microsecond=0).isoformat() }, 'currency': {'standard': 'ISO 4217'}, 'pa_rate': {'unit': 'percent per annum'}, 'pm_rate': {'unit': 'percent per month'}, 'pd_rate': {'unit': 'per mil per day'} } xml = new_xml('') tdebt = xml_decorate(xml.new_tag('debt'), dec) xml.append(tdebt) for key in ('title', 'note', 'internal_note'): tag = xml.new_tag(key) tag.append(xml_escape(debt.__getattribute__(key))) tdebt.append(tag) tag = xml_decorate(xml.new_tag('currency'), dec) tag.append(debt.currency) tdebt.append(tag) tag = xml.new_tag('rounding') tag.append(str(debt.rounding)) tdebt.append(tag) titr = xml.new_tag('interest') interest = debt.interest model = interest.model titr['model'] = model if model == 'fixed': tag = xml.new_tag('amount') tag.append('{:.2f}'.format(interest.fixed_amount)) titr.append(tag) elif model == 'per_annum': tag = xml_decorate(xml.new_tag('pa_rate'), dec) tag.append('{:.6f}'.format(interest.rate)) titr.append(tag) elif model == 'per_mensem': tag = xml_decorate(xml.new_tag('pm_rate'), dec) tag.append('{:.6f}'.format(interest.rate)) titr.append(tag) elif model == 'per_diem': tag = xml_decorate(xml.new_tag('pd_rate'), dec) tag.append('{:.6f}'.format(interest.rate)) titr.append(tag) if model in {'per_annum', 'per_mensem'}: tag = xml.new_tag('day_count_convention') tag.append(interest.day_count_convention) titr.append(tag) tdebt.append(titr) trs = xml.new_tag('transactions') for trn in debt.transactions: ttrn = xml.new_tag(trn.transaction_type) tag = xml.new_tag('description') tag.append(xml_escape(trn.description)) ttrn.append(tag) tag = xml.new_tag('date') tag.append(trn.date.isoformat()) ttrn.append(tag) if hasattr(trn, 'amount'): tag = xml.new_tag('amount') tag.append('{:.2f}'.format(trn.amount)) ttrn.append(tag) if hasattr(trn, 'repayment_preference'): tag = xml.new_tag('repayment_preference') tag.append(trn.repayment_preference) ttrn.append(tag) trs.append(ttrn) tdebt.append(trs) return str(xml).encode('utf-8') + b'\n'
def get_fx_rate(curr, dat, log=None, use_fixed=False, log_fixed=None): LOGGER.debug( 'FX rate requested, currency "{0}" for {1.year:d}-{1.month:02d}-{1.day:02d}, fixed "{2}"' .format(curr, dat, use_fixed)) fixed_list = { 'XEU': {'currency_to': 'EUR', 'fixed_rate': 1, 'date_from': date(1999, 1, 1)}, 'ATS': {'currency_to': 'EUR', 'fixed_rate': 13.7603, 'date_from': date(1998, 12, 31)}, 'BEF': {'currency_to': 'EUR', 'fixed_rate': 40.3399, 'date_from': date(1998, 12, 31)}, 'NLG': {'currency_to': 'EUR', 'fixed_rate': 2.20371, 'date_from': date(1998, 12, 31)}, 'FIM': {'currency_to': 'EUR', 'fixed_rate': 5.94573, 'date_from': date(1998, 12, 31)}, 'FRF': {'currency_to': 'EUR', 'fixed_rate': 6.55957, 'date_from': date(1998, 12, 31)}, 'DEM': {'currency_to': 'EUR', 'fixed_rate': 1.95583, 'date_from': date(1998, 12, 31)}, 'IEP': {'currency_to': 'EUR', 'fixed_rate': .787564, 'date_from': date(1998, 12, 31)}, 'ITL': {'currency_to': 'EUR', 'fixed_rate': 1936.27, 'date_from': date(1998, 12, 31)}, 'LUF': {'currency_to': 'EUR', 'fixed_rate': 40.3399, 'date_from': date(1998, 12, 31)}, 'MCF': {'currency_to': 'EUR', 'fixed_rate': 6.55957, 'date_from': date(1998, 12, 31)}, 'PTE': {'currency_to': 'EUR', 'fixed_rate': 200.482, 'date_from': date(1998, 12, 31)}, 'SML': {'currency_to': 'EUR', 'fixed_rate': 1936.27, 'date_from': date(1998, 12, 31)}, 'ESP': {'currency_to': 'EUR', 'fixed_rate': 166.386, 'date_from': date(1998, 12, 31)}, 'VAL': {'currency_to': 'EUR', 'fixed_rate': 1936.27, 'date_from': date(1998, 12, 31)}, 'GRD': {'currency_to': 'EUR', 'fixed_rate': 340.75, 'date_from': date(2000, 6, 19)}, 'SIT': {'currency_to': 'EUR', 'fixed_rate': 239.64, 'date_from': date(2006, 7, 11)}, 'CYP': {'currency_to': 'EUR', 'fixed_rate': .585274, 'date_from': date(2007, 7, 10)}, 'MTL': {'currency_to': 'EUR', 'fixed_rate': .4293, 'date_from': date(2007, 7, 10)}, 'SKK': {'currency_to': 'EUR', 'fixed_rate': 30.126, 'date_from': date(2008, 7, 8)}, 'EEK': {'currency_to': 'EUR', 'fixed_rate': 15.6466, 'date_from': date(2010, 7, 13)}, 'ROL': {'currency_to': 'RON', 'fixed_rate': 10000, 'date_from': date(2005, 7, 1)}, 'RUR': {'currency_to': 'RUB', 'fixed_rate': 1000, 'date_from': date(1998, 1, 1)}, 'MXP': {'currency_to': 'MXN', 'fixed_rate': 1000, 'date_from': date(1993, 1, 1)}, 'UAK': {'currency_to': 'UAH', 'fixed_rate': 100000, 'date_from': date(1996, 9, 2)}, 'TRL': {'currency_to': 'TRY', 'fixed_rate': 1000000, 'date_from': date(2005, 1, 1)}, 'BGL': {'currency_to': 'BGN', 'fixed_rate': 1000, 'date_from': date(1999, 7, 5)}, 'PLZ': {'currency_to': 'PLN', 'fixed_rate': 10000, 'date_from': date(1995, 1, 1)}, 'CSD': {'currency_to': 'RSD', 'fixed_rate': 1, 'date_from': date(2003, 1, 1)}, } today = date.today() if dat.year < 1991 or dat > today: return None, None, None, 'Chybné datum, data nejsou k disposici' rat = FXrate.objects.filter(date=dat) if rat: txt = rat[0].text else: surl = ( 'https://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.xml?' 'date={0.day:d}.{0.month:d}.{0.year:d}'.format(dat)) txt = getcache(surl, DOWNLOAD_REPEAT)[0] if not txt: LOGGER.warning('No connection to CNB server') return None, None, None, 'Chyba spojení se serverem ČNB' try: soup = new_xml(txt) assert soup assert soup.find( 'tabulka', {'typ': 'XML_TYP_CNB_KURZY_DEVIZOVEHO_TRHU'}) dreq = soup.find('kurzy', {'banka': 'CNB'})['datum'] dreq = date(int(dreq[6:]), int(dreq[3:5]), int(dreq[:2])) except: LOGGER.error('Invalid FX table structure for {0.year:d}-{0.month:02d}-{0.day:02d}'.format(dat)) return None, None, None, 'Chyba struktury kursové tabulky' if not rat and (dreq == dat or (today - dat) > DOWNLOAD_WAIT): FXrate(date=dat, text=txt).save() lin = soup.find('radek', {'kod': curr}) frat = 1 curr_rq = curr if not lin: if use_fixed and curr in fixed_list and fixed_list[curr]['date_from'] <= dat: curr = fixed_list[curr]['currency_to'] lin = soup.find('radek', {'kod': curr}) if not lin: return None, None, dreq, 'Kurs není v kursové tabulce' frat = fixed_list[curr_rq]['fixed_rate'] if log_fixed != None: log_fixed.append( {'currency_from': curr_rq, 'currency_to': fixed_list[curr_rq]['currency_to'], 'rate': fixed_list[curr_rq]['fixed_rate'], 'date_from': fixed_list[curr_rq]['date_from']}) else: return None, None, dreq, 'Kurs není v kursové tabulce' try: qty = int(lin['mnozstvi']) if lin.has_attr('kurz'): rate = lin['kurz'] elif lin.has_attr('pomer'): rate = lin['pomer'] rate = float(rate.replace(',', '.')) except: LOGGER.error('Invalid FX table line for {0.year:d}-{0.month:02d}-{0.day:02d}'.format(dat)) return None, None, dreq, 'Chyba řádku kursové tabulky' if log != None: log.append( {'currency': curr, 'quantity': qty, 'rate': rate, 'date_required': dat, 'date': dreq}) return rate / frat, qty, dreq, None
def xmllist(request): LOGGER.debug('XML list accessed', request, request.GET) reqd = request.GET.copy() try: par = g2p(reqd) res = Vec.objects.filter(**par).order_by('firstAction', 'rocnik', 'bc', 'idOsobyPuvodce').distinct() except: raise Http404 total = res.count() if total > EXLIM: return render( request, 'exlim.xhtml', {'app': APP, 'page_title': EXLIM_TITLE, 'limit': EXLIM, 'total': total, 'back': reverse('pir:mainpage')}) dec = { 'insolvencies': { 'xmlns': 'http://' + LOCAL_SUBDOMAIN, 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': 'http://{} {}/static/{}-{}.xsd'.format(LOCAL_SUBDOMAIN, LOCAL_URL, APP, APPVERSION), 'application': APP, 'version': APPVERSION, 'created': datetime.now().replace(microsecond=0).isoformat() } } xml = new_xml('') tag_insolvencies = xml_decorate(xml.new_tag('insolvencies'), dec) xml.append(tag_insolvencies) for item in res: tag_insolvency = xml.new_tag('insolvency') tag_insolvencies.append(tag_insolvency) tag_court = xml.new_tag('court') tag_insolvency.append(tag_court) tag_court['id'] = item.idOsobyPuvodce tag_court.append(L2N[item.idOsobyPuvodce]) tag_ref = xml.new_tag('ref') tag_insolvency.append(tag_ref) tag_court = xml.new_tag('court') tag_court.append(L2S[item.idOsobyPuvodce]) tag_ref.append(tag_court) tag_senate = xml.new_tag('senate') tag_senate.append(str(item.senat)) tag_ref.append(tag_senate) tag_register = xml.new_tag('register') tag_register.append('INS') tag_ref.append(tag_register) tag_number = xml.new_tag('number') tag_number.append(str(item.bc)) tag_ref.append(tag_number) tag_year = xml.new_tag('year') tag_year.append(str(item.rocnik)) tag_ref.append(tag_year) if item.druhStavRizeni: tag_state = xml.new_tag('state') tag_state.append(S2D[item.druhStavRizeni.desc]) tag_insolvency.append(tag_state) tag_debtors = xml.new_tag('debtors') tag_insolvency.append(tag_debtors) xml_addparties(getosoby(item, 'debtor'), xml, tag_debtors, 'debtor') tag_trustees = xml.new_tag('trustees') tag_insolvency.append(tag_trustees) xml_addparties(getosoby(item, 'trustee'), xml, tag_trustees, 'trustee') if 'creditors' in reqd: tag_creditors = xml.new_tag('creditors') tag_insolvency.append(tag_creditors) xml_addparties(getosoby(item, 'motioner', 'creditor'), xml, tag_creditors, 'creditor') response = HttpResponse( str(xml).encode('utf-8') + b'\n', content_type='text/xml; charset=utf-8') response['Content-Disposition'] = 'attachment; filename=Insolvence.xml' return response
def get_fx_rate(curr, dat, log=None, use_fixed=False, log_fixed=None): LOGGER.debug( 'FX rate requested, currency "{0}" for {1.year:d}-{1.month:02d}-{1.day:02d}, fixed "{2}"' .format(curr, dat, use_fixed)) fixed_list = { 'XEU': { 'currency_to': 'EUR', 'fixed_rate': 1, 'date_from': date(1999, 1, 1) }, 'ATS': { 'currency_to': 'EUR', 'fixed_rate': 13.7603, 'date_from': date(1998, 12, 31) }, 'BEF': { 'currency_to': 'EUR', 'fixed_rate': 40.3399, 'date_from': date(1998, 12, 31) }, 'NLG': { 'currency_to': 'EUR', 'fixed_rate': 2.20371, 'date_from': date(1998, 12, 31) }, 'FIM': { 'currency_to': 'EUR', 'fixed_rate': 5.94573, 'date_from': date(1998, 12, 31) }, 'FRF': { 'currency_to': 'EUR', 'fixed_rate': 6.55957, 'date_from': date(1998, 12, 31) }, 'DEM': { 'currency_to': 'EUR', 'fixed_rate': 1.95583, 'date_from': date(1998, 12, 31) }, 'IEP': { 'currency_to': 'EUR', 'fixed_rate': .787564, 'date_from': date(1998, 12, 31) }, 'ITL': { 'currency_to': 'EUR', 'fixed_rate': 1936.27, 'date_from': date(1998, 12, 31) }, 'LUF': { 'currency_to': 'EUR', 'fixed_rate': 40.3399, 'date_from': date(1998, 12, 31) }, 'MCF': { 'currency_to': 'EUR', 'fixed_rate': 6.55957, 'date_from': date(1998, 12, 31) }, 'PTE': { 'currency_to': 'EUR', 'fixed_rate': 200.482, 'date_from': date(1998, 12, 31) }, 'SML': { 'currency_to': 'EUR', 'fixed_rate': 1936.27, 'date_from': date(1998, 12, 31) }, 'ESP': { 'currency_to': 'EUR', 'fixed_rate': 166.386, 'date_from': date(1998, 12, 31) }, 'VAL': { 'currency_to': 'EUR', 'fixed_rate': 1936.27, 'date_from': date(1998, 12, 31) }, 'GRD': { 'currency_to': 'EUR', 'fixed_rate': 340.75, 'date_from': date(2000, 6, 19) }, 'SIT': { 'currency_to': 'EUR', 'fixed_rate': 239.64, 'date_from': date(2006, 7, 11) }, 'CYP': { 'currency_to': 'EUR', 'fixed_rate': .585274, 'date_from': date(2007, 7, 10) }, 'MTL': { 'currency_to': 'EUR', 'fixed_rate': .4293, 'date_from': date(2007, 7, 10) }, 'SKK': { 'currency_to': 'EUR', 'fixed_rate': 30.126, 'date_from': date(2008, 7, 8) }, 'EEK': { 'currency_to': 'EUR', 'fixed_rate': 15.6466, 'date_from': date(2010, 7, 13) }, 'ROL': { 'currency_to': 'RON', 'fixed_rate': 10000, 'date_from': date(2005, 7, 1) }, 'RUR': { 'currency_to': 'RUB', 'fixed_rate': 1000, 'date_from': date(1998, 1, 1) }, 'MXP': { 'currency_to': 'MXN', 'fixed_rate': 1000, 'date_from': date(1993, 1, 1) }, 'UAK': { 'currency_to': 'UAH', 'fixed_rate': 100000, 'date_from': date(1996, 9, 2) }, 'TRL': { 'currency_to': 'TRY', 'fixed_rate': 1000000, 'date_from': date(2005, 1, 1) }, 'BGL': { 'currency_to': 'BGN', 'fixed_rate': 1000, 'date_from': date(1999, 7, 5) }, 'PLZ': { 'currency_to': 'PLN', 'fixed_rate': 10000, 'date_from': date(1995, 1, 1) }, 'CSD': { 'currency_to': 'RSD', 'fixed_rate': 1, 'date_from': date(2003, 1, 1) }, } today = date.today() if dat.year < 1991 or dat > today: return None, None, None, 'Chybné datum, data nejsou k disposici' rat = FXrate.objects.filter(date=dat) if rat: txt = rat[0].text else: surl = ( 'https://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.xml?' 'date={0.day:d}.{0.month:d}.{0.year:d}'.format(dat)) txt = getcache(surl, DOWNLOAD_REPEAT)[0] if not txt: LOGGER.warning('No connection to CNB server') return None, None, None, 'Chyba spojení se serverem ČNB' try: soup = new_xml(txt) assert soup assert soup.find('tabulka', {'typ': 'XML_TYP_CNB_KURZY_DEVIZOVEHO_TRHU'}) dreq = soup.find('kurzy', {'banka': 'CNB'})['datum'] dreq = date(int(dreq[6:]), int(dreq[3:5]), int(dreq[:2])) except: LOGGER.error( 'Invalid FX table structure for {0.year:d}-{0.month:02d}-{0.day:02d}' .format(dat)) return None, None, None, 'Chyba struktury kursové tabulky' if not rat and (dreq == dat or (today - dat) > DOWNLOAD_WAIT): FXrate(date=dat, text=txt).save() lin = soup.find('radek', {'kod': curr}) frat = 1 curr_rq = curr if not lin: if use_fixed and curr in fixed_list and fixed_list[curr][ 'date_from'] <= dat: curr = fixed_list[curr]['currency_to'] lin = soup.find('radek', {'kod': curr}) if not lin: return None, None, dreq, 'Kurs není v kursové tabulce' frat = fixed_list[curr_rq]['fixed_rate'] if log_fixed != None: log_fixed.append({ 'currency_from': curr_rq, 'currency_to': fixed_list[curr_rq]['currency_to'], 'rate': fixed_list[curr_rq]['fixed_rate'], 'date_from': fixed_list[curr_rq]['date_from'] }) else: return None, None, dreq, 'Kurs není v kursové tabulce' try: qty = int(lin['mnozstvi']) if lin.has_attr('kurz'): rate = lin['kurz'] elif lin.has_attr('pomer'): rate = lin['pomer'] rate = float(rate.replace(',', '.')) except: LOGGER.error( 'Invalid FX table line for {0.year:d}-{0.month:02d}-{0.day:02d}'. format(dat)) return None, None, dreq, 'Chyba řádku kursové tabulky' if log != None: log.append({ 'currency': curr, 'quantity': qty, 'rate': rate, 'date_required': dat, 'date': dreq }) return rate / frat, qty, dreq, None
def xmllist(request): LOGGER.debug('XML list accessed', request, request.GET) reqd = request.GET.copy() try: par = g2p(reqd) res = Decision.objects.filter(**par).order_by('date', 'pk').distinct() except: raise Http404 total = res.count() if total > EXLIM: return render( request, 'exlim.xhtml', {'app': APP, 'page_title': EXLIM_TITLE, 'limit': EXLIM, 'total': total, 'back': reverse('udn:mainpage')}) dec = { 'decisions': { 'xmlns': 'http://' + LOCAL_SUBDOMAIN, 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': 'http://{} {}/static/{}-{}.xsd'.format(LOCAL_SUBDOMAIN, LOCAL_URL, APP, APPVERSION), 'application': APP, 'version': APPVERSION, 'created': datetime.now().replace(microsecond=0).isoformat() } } xml = new_xml('') tag_decisions = xml_decorate(xml.new_tag('decisions'), dec) xml.append(tag_decisions) for item in res: tag_decision = xml.new_tag('decision') tag_decisions.append(tag_decision) tag_court = xml.new_tag('court') tag_decision.append(tag_court) tag_court['id'] = SUPREME_ADMINISTRATIVE_COURT tag_court.append(SUPREME_ADMINISTRATIVE_COURT_NAME) tag_date = xml.new_tag('date') tag_decision.append(tag_date) tag_date.append(item.date.isoformat()) tag_ref = xml.new_tag('ref') tag_decision.append(tag_ref) tag_senate = xml.new_tag('senate') tag_senate.append(str(item.senate)) tag_ref.append(tag_senate) tag_register = xml.new_tag('register') tag_register.append(item.register) tag_ref.append(tag_register) tag_number = xml.new_tag('number') tag_number.append(str(item.number)) tag_ref.append(tag_number) tag_year = xml.new_tag('year') tag_year.append(str(item.year)) tag_ref.append(tag_year) tag_page = xml.new_tag('page') tag_page.append(str(item.page)) tag_ref.append(tag_page) tag_agenda = xml.new_tag('agenda') tag_decision.append(tag_agenda) tag_agenda.append(item.agenda.desc) tag_parties = xml.new_tag('parties') tag_decision.append(tag_parties) for party in item.parties.values(): tag_party = xml.new_tag('party') tag_parties.append(tag_party) tag_party.append(party['name']) tag_files = xml.new_tag('files') tag_decision.append(tag_files) tag_file = xml.new_tag('file') tag_files.append(tag_file) tag_file['type'] = 'abridged' tag_file.append(join(REPO_PREFIX, item.filename)) if item.anonfilename: tag_file = xml.new_tag('file') tag_files.append(tag_file) tag_file['type'] = 'anonymized' tag_file.append(join(REPO_PREFIX, item.anonfilename)) response = HttpResponse( str(xml).encode('utf-8') + b'\n', content_type='text/xml; charset=utf-8') response['Content-Disposition'] = 'attachment; filename=Rozhodnuti.xml' return response