Created
January 7, 2016 04:55
-
-
Save gmmephisto/1242cce8945507b807fb to your computer and use it in GitHub Desktop.
ztickets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
from __future__ import print_function | |
import argparse | |
import json | |
import requests | |
from lxml.html import parse | |
def get_kassir_data(event_id): | |
"""Returns tickets info for specified event.""" | |
url = "https://msk.kassir.ru/kassir/scheme/gethallinfo?eventId=%s" % (event_id,) | |
response = requests.get(url, timeout=5, allow_redirects=False) | |
try: | |
response.raise_for_status() | |
except requests.HTTPError as e: | |
print("Error while loading data from kassir.ru: %s" % (e,)) | |
raise | |
result = None | |
try: | |
result = json.loads(response.text) | |
except Exception as e: | |
print("Malformed response from kassir.ru: %s" % (e,)) | |
raise | |
return result | |
def get_redkassa_data(seance_id): | |
"""Returns tickets info for specified seance. | |
de579fcf-6ad8-4367-ab3b-48ff763a9aab | |
""" | |
url = "http://redkassa.ru/quota/Quota?seanceId=%s" % (seance_id,) | |
url += "&sortingMode=PriceAsc" | |
url += "§orSeatsLocation=Top" | |
document = parse(url) | |
return [ unicode(e.text.encode("latin-1"), "utf-8") | |
for e in document.xpath("//table/tr[@class='event ']/td[2]") ] | |
def main(): | |
"""Script's main function.""" | |
parser = argparse.ArgumentParser("Z Tickets.") | |
parser.add_argument("seats", nargs="?", default=u"партер", help="Seats type.") | |
args = parser.parse_args() | |
seats = unicode(args.seats, "utf-8") if not isinstance(args.seats, unicode) else args.seats | |
seats = seats.lower() | |
print("kassir.ru:") | |
tickets = get_kassir_data(27532) | |
for key, data in tickets.iteritems(): | |
if seats in data["name"].lower(): | |
print("{0} - {1}".format(data["count"], data["name"]).encode("utf-8")) | |
print("redkassa.ru:") | |
tickets = get_redkassa_data("de579fcf-6ad8-4367-ab3b-48ff763a9aab") | |
for data in tickets: | |
if seats in data.lower(): | |
print("# - {0}".format(data)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment