Merge branch 'master' of gitlab.com:matteodelabre/wikimedica-disease-search
This commit is contained in:
commit
9f3459fd24
|
@ -1,4 +1,8 @@
|
|||
node_modules
|
||||
__pycache__
|
||||
.cache
|
||||
dist
|
||||
# Node.js
|
||||
node_modules/
|
||||
.cache/
|
||||
dist/
|
||||
|
||||
# Python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,15 +1,38 @@
|
|||
import logging
|
||||
import requests
|
||||
import urllib3
|
||||
|
||||
# Session de requêtage HTTP
|
||||
session = requests.Session()
|
||||
|
||||
# Réalise 10 essais de récupération de chaque page, en augmentant
|
||||
# progressivement le délai entre chaque essai
|
||||
# Objet pour afficher le journal d’exécution
|
||||
logger = logging.getLogger('fetch.http')
|
||||
|
||||
|
||||
class LoggingAdapter(requests.adapters.HTTPAdapter):
|
||||
"""
|
||||
Adapteur de requêtes vérifiant le nombre d’accès réalisés par seconde.
|
||||
"""
|
||||
def __init__(self):
|
||||
# Réessaie jusqu’à dix fois la récupération de chaque page, en
|
||||
# augmentant progressivement le délai entre chaque essai
|
||||
retry = urllib3.util.Retry(total=10, backoff_factor=0.3)
|
||||
adapter = requests.adapters.HTTPAdapter(max_retries=retry)
|
||||
session.mount('http', adapter)
|
||||
session.mount('https', adapter)
|
||||
super(LoggingAdapter, self).__init__(max_retries=retry)
|
||||
|
||||
def send(
|
||||
self, request, stream=False, timeout=None, verify=True,
|
||||
cert=None, proxies=None
|
||||
):
|
||||
logger.debug('{} {}'.format(request.method, request.url))
|
||||
return super(LoggingAdapter, self).send(
|
||||
request, stream=stream, timeout=timeout,
|
||||
verify=verify, cert=cert, proxies=proxies
|
||||
)
|
||||
|
||||
|
||||
adapter = LoggingAdapter()
|
||||
session.mount('http://', adapter)
|
||||
session.mount('https://', adapter)
|
||||
|
||||
# Identification du robot
|
||||
session.headers['User-Agent'] = (
|
||||
|
|
|
@ -28,12 +28,14 @@ def _year_date_distance(a, b):
|
|||
"""
|
||||
Calcule la distance entre deux jours de l’année.
|
||||
|
||||
:example: _year_date_distance(10, 360) == 15
|
||||
:example: _year_date_distance(numpy.array([10, 182, 355]), 182)
|
||||
== [172, 0, 173]
|
||||
:param a: Première valeur (peut être un tableau numpy).
|
||||
:param b: Seconde valeur (peut être un tableau numpy).
|
||||
:return: Valeur de la distance.
|
||||
|
||||
>>> _year_date_distance(10, 360)
|
||||
15
|
||||
>>> _year_date_distance(numpy.array([10, 182, 355]), 182)
|
||||
[172, 0, 173]
|
||||
"""
|
||||
return numpy.stack((
|
||||
numpy.mod(a - b, len(year_all_days)),
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
import calendar
|
||||
import collections
|
||||
from datetime import datetime
|
||||
|
@ -8,7 +9,7 @@ from matplotlib import pyplot
|
|||
import sys
|
||||
|
||||
# Objet pour afficher le journal d’exécution
|
||||
logger = logging.getLogger('pageviews')
|
||||
logger = logging.getLogger('plot_pageviews')
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
if len(sys.argv) < 4:
|
||||
|
|
Loading…
Reference in New Issue