<commit_before>import os
import requests

from BeautifulSoup import BeautifulSoup
from PIL import Image, ImageDraw, ImageFont

from django.http import HttpResponse

PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))
here = lambda *x: os.path.join(PROJECT_ROOT, '..', *x)
HEADER_FONT = here('fonts', 'Playfair_Display', 'PlayfairDisplay-Bold.ttf')
CONTENT_FONT = here('fonts', 'Open_Sans', 'OpenSans-Regular.ttf')

USER_AGENT = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) '
              'Gecko/20100101 Firefox/31.0')

MARGIN_LEFT = 10
VALID_STATIONS = ['london liverpool street']

HEADERS = {
    'User-Agent': USER_AGENT
}

def get_timetable(shortcode):
    url = ('http://www.abelliogreateranglia.co.uk/travel-information'
           '/journey-planning/live-departures/station/%s' % shortcode)
    response = requests.get(url, headers=HEADERS)
    soup = BeautifulSoup(response.content)
    columns = ['destination', 'time', 'status', 'origin', 'operator']
    timetable = []
    for row in soup.findAll('tr'):
        if row.find('th'):
            continue
        row_data = dict([(k, v.text) for k, v in zip(columns, row.findAll('td'))])
        timetable.append(row_data)
    return [d for d in timetable if d['destination'].lower() in VALID_STATIONS]

<commit_msg>Retry once if the response is not 200.<commit_after>import os
import requests

from BeautifulSoup import BeautifulSoup
from PIL import Image, ImageDraw, ImageFont

from django.http import HttpResponse

PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))
here = lambda *x: os.path.join(PROJECT_ROOT, '..', *x)
HEADER_FONT = here('fonts', 'Playfair_Display', 'PlayfairDisplay-Bold.ttf')
CONTENT_FONT = here('fonts', 'Open_Sans', 'OpenSans-Regular.ttf')

USER_AGENT = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) '
              'Gecko/20100101 Firefox/31.0')

MARGIN_LEFT = 10
VALID_STATIONS = ['london liverpool street']

HEADERS = {
    'User-Agent': USER_AGENT
}

def get_timetable(shortcode):
    url = ('http://www.abelliogreateranglia.co.uk/travel-information'
           '/journey-planning/live-departures/station/%s' % shortcode)
    response = requests.get(url, headers=HEADERS)
    if not response.status_code == 200:
        response = requests.get(url, headers=HEADERS)
    soup = BeautifulSoup(response.content)
    columns = ['destination', 'time', 'status', 'origin', 'operator']
    timetable = []
    for row in soup.findAll('tr'):
        if row.find('th'):
            continue
        row_data = dict([(k, v.text) for k, v in zip(columns, row.findAll('td'))])
        timetable.append(row_data)
    return [d for d in timetable if d['destination'].lower() in VALID_STATIONS]


{'fraction_non_alphanumeric': 0.14085027726432534, 'fraction_numerical': 0.0177449168207024, 'mean_word_length': 3.884476534296029, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2191103', 'n_tokens_mistral': 973, 'n_tokens_neox': 912, 'n_words': 210}