Skip to content

Instantly share code, notes, and snippets.

@josepanguera
Created March 28, 2017 22:03
Show Gist options
  • Save josepanguera/f84e84aa0d49797d7c7d0fdff229e45b to your computer and use it in GitHub Desktop.
Save josepanguera/f84e84aa0d49797d7c7d0fdff229e45b to your computer and use it in GitHub Desktop.
Espoilertv API
from datetime import datetime
from bs4 import BeautifulSoup
import requests
class Espoilertv:
BASE_URL = 'http://espoilertv.com/'
def __init__(self, email, password):
payload = {
'mail': email,
'pass': password,
}
session = requests.Session()
session.post(self.BASE_URL + 'serv/asincrono/logOn.php', data=payload)
self.session = session
def create_or_update_episode(self, series, season, number, date, title, id_=0):
payload = {
'obj': 'epi',
'idSerie': series,
's': season,
'e': number,
'fecha': date.strftime("%d/%m/%Y"),
'tit': title,
'epiId': id_ # If 0 (default) create episode
}
r = self.session.post(self.BASE_URL + 'tools/php/reqGuardarSerie.php', data=payload)
def series_info(self, series):
def parse_episode(soup):
airdate = soup.find('input', {'name': 'epiFecha'}).attrs['value']
airdate = datetime.strptime(airdate, '%d/%m/%Y')
return {
'id': soup.find('input', {'name': 'epiId'}).attrs['value'],
'season': soup.find('input', {'name': 'epiTem'}).attrs['value'],
'number': soup.find('input', {'name': 'epiNro'}).attrs['value'],
'title': soup.find('input', {'name': 'epiTit'}).attrs['value'],
'date': airdate.date(),
}
r = self.session.get(self.BASE_URL + 'tools/serie.php', params={'id': series})
soup = BeautifulSoup(r.text, 'html.parser')
info = {}
info['episodes'] = [parse_episode(e) for e in soup.find(id="form_epis")('fieldset')]
return info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment