from sources import ChickenSource, ChickenPlace, GeoPoint from twisted.internet import defer from twisted.web.client import getPage from lib import cache import json import logging BASE_URL = "http://www.kfc.co.uk/our-restaurants/search?latitude={0}&longitude={1}&radius=10&storeTypes=" kfc_cache = cache.getCache("kfc_places") class KFCSource(ChickenSource): NAME = "KFC" MENUS = False NEEDS_POSTCODE = False @defer.inlineCallbacks def GetAvailablePlaces(self, location): cache_result = kfc_cache.get(location.geohash) if not cache_result is None: logging.info("Got KFC's from cache") defer.returnValue(cache_result) try: kfc_result = yield getPage( BASE_URL.format(location.geopoint.lat, location.geopoint.long), timeout=5) except Exception: defer.returnValue({}) json_response = json.loads(kfc_result)
from sources import ChickenSource, ChickenPlace, GeoPoint from twisted.internet import defer from twisted.web.client import getPage from lib import cache import json import logging BASE_URL = "http://www.kfc.co.uk/our-restaurants/search?latitude={0}&longitude={1}&radius=10&storeTypes=" kfc_cache = cache.getCache("kfc_places") class KFCSource(ChickenSource): NAME = "KFC" MENUS = False NEEDS_POSTCODE = False @defer.inlineCallbacks def GetAvailablePlaces(self, location): cache_result = kfc_cache.get(location.geohash) if not cache_result is None: logging.info("Got KFC's from cache") defer.returnValue(cache_result) try: kfc_result = yield getPage(BASE_URL.format(location.geopoint.lat, location.geopoint.long), timeout=5) except Exception: defer.returnValue({}) json_response = json.loads(kfc_result)
from bs4 import BeautifulSoup from ampoule import child, pool from twisted.protocols import amp import time import json import traceback IOS_USER_AGENT = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) "\ "AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 "\ "Safari/6533.18.5" HOST = "http://www.just-eat.co.uk" BASE_URL = HOST + "/area/{0}" ALLOWED_FOOD_TYPES = set(("pizza","kebabs","american")) menu_cache = cache.getCache("menu_cache") HAS_LXML = False try: import lxml HAS_LXML = True del lxml except ImportError: print "Lxml not detected: Consider installing it for a speed boost" def get_parser(text): if HAS_LXML: return BeautifulSoup(text, "lxml") return BeautifulSoup(text) class FetchChickenPlaceCommand(amp.Command):
# Geocode stuff from twisted.internet import defer from twisted.web.client import getPage from sources import GeoPoint import settings, json, urllib from lib import cache, geohash import logging import math BASE_URI = "http://where.yahooapis.com/geocode" address_cache = cache.getCache("geo_address") postcode_cache = cache.getCache("geo_postcode") @defer.inlineCallbacks def geopoint_to_postcode(geopoint, ghash=None): result = yield geopoint_to_address(geopoint, ghash) pcode = result["postal"] or result["uzip"] if not pcode: defer.returnValue(None) else: defer.returnValue(pcode.split(" ")[0]) @defer.inlineCallbacks def geopoint_to_address(geopoint, ghash=None): if ghash is None: ghash = geohash.encode(geopoint.lat, geopoint.long, precision=10) cache_result = postcode_cache.get(ghash)
# Geocode stuff from twisted.internet import defer from twisted.web.client import getPage from sources import GeoPoint import settings, json, urllib from lib import cache, geohash import logging import math BASE_URI = "http://where.yahooapis.com/geocode" address_cache = cache.getCache("geo_address") postcode_cache = cache.getCache("geo_postcode") @defer.inlineCallbacks def geopoint_to_postcode(geopoint, ghash=None): result = yield geopoint_to_address(geopoint, ghash) pcode = result["postal"] or result["uzip"] if not pcode: defer.returnValue(None) else: defer.returnValue(pcode.split(" ")[0]) @defer.inlineCallbacks def geopoint_to_address(geopoint, ghash=None): if ghash is None: ghash = geohash.encode(geopoint.lat, geopoint.long, precision=10) cache_result = postcode_cache.get(ghash) if cache_result is not None: defer.returnValue(cache_result)
from bs4 import BeautifulSoup from ampoule import child, pool from twisted.protocols import amp import time import json import traceback IOS_USER_AGENT = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) "\ "AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 "\ "Safari/6533.18.5" HOST = "http://www.just-eat.co.uk" BASE_URL = HOST + "/area/{0}" ALLOWED_FOOD_TYPES = set(("pizza", "kebabs", "american")) menu_cache = cache.getCache("menu_cache") HAS_LXML = False try: import lxml HAS_LXML = True del lxml except ImportError: print "Lxml not detected: Consider installing it for a speed boost" def get_parser(text): if HAS_LXML: return BeautifulSoup(text, "lxml") return BeautifulSoup(text)