A
A
askhabaliev2021-04-11 01:06:30
Python
askhabaliev, 2021-04-11 01:06:30

Why is the request taking so long to process?

import requests
import pandas as pd
import numpy as np
import datetime as date
import pandahouse as ph
import matplotlib.pyplot as plt
import xml.etree.ElementTree as et
from prophet import Prophet


daterange = pd.date_range('2020-06-01', '2020-10-31')


currencies = pd.DataFrame()
info_currencies = pd.DataFrame()

for single_date in daterange:
    date = single_date.strftime("%d.%m.%Y")
    url = 'http://www.cbr.ru/scripts/XML_daily.asp?date_req=%s' % date
    root = et.fromstring(requests.get(url).content)
    
    for item in root.findall('.//Valute'):
        data = {}
        for child in list(item):
            data.update({child.tag: child.text})
        currencies = currencies \
        .append({'name': data['CharCode'], 'value': data['Value'], 'date': date}, ignore_index=True)
        info_currencies = info_currencies \
        .append({'name': data['CharCode'], 'dsh': data['Name']}, ignore_index=True)


in the afternoon everything loaded in a couple of seconds

now you have to wait 10 minutes or even closes

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2021-04-12
@askhabaliev

If during the day everything works quickly with absolutely the same parameters, then the problem is in the Internet or the cbr.ru server. There is not much help here, except to parallelize queries instead of executing them sequentially in a loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question