Example #1
0
 def test_remove_ol(self):
     added = [{
              "id": "725197847591760",
              "cover": {
                 "cover_id": "1012103818809849",
                 "offset_x": 0,
                 "offset_y": 0,
                 "source": "https://scontent.xx.fbcdn.net/hphotos-xtf1/v/t1.0-9/s720x720/11694763_1012103818809849_5115312729383944165_n.jpg?oh=a5d0b6034afaef28beffebfca765c81e&oe=5656B661",
                 "id": "1012103818809849"
              },
              "name": "Off the Grid: North Berkeley (Sunday Dinner)",
              "description": "Every Sunday from 5pm to 9pm, grab bites from a rotating list of 8-10 artisanal street food vendors.\n\nLocation: Corner of Delaware and Sacramento St \u0040 North Berkeley Bart Station \n\nTime: Sundays from 5pm to 8pm - Launching this Sunday, February 9th \nDownload Off the Grid App for amenities around this market! http://offthegridsf.com/app",
              "start_time": "2015-08-02T17:00:00-0700",
              "location": " North Berkeley Bart Station, 1750 Sacramento Street, Berkeley CA",
              "end_time": "2015-08-02T21:00:00-0700"
           },
           {
              "id": "1474801892813940",
              "cover": {
                 "cover_id": "1012103752143189",
                 "offset_x": 0,
                 "offset_y": 0,
                 "source": "https://scontent.xx.fbcdn.net/hphotos-xpt1/v/t1.0-9/11140228_1012103752143189_5894681009158221868_n.jpg?oh=6e1de6957ee86e541adb8aea5cd70b19&oe=5615D011",
                 "id": "1012103752143189"
              },
              "name": "OtG: San Jose \u0040 Evergreen Village Square",
              "description": "Off the Grid is joining the weekend fun at Evergreen Village Square. Bringing food trucks, live music and special programming, Off the Grid is ready to fill the Saturday void between Music, Art & Wine Friday nights and the Sunday Farmer's Markets. Look out for special collaborations with \nSan Jose Made (SJMADE) as we feature local makers through live cooking demos & more!\n\nWhere: 4075 Evergreen Village Square, San Jose\n\nWhen: Saturday, 11:00 a.m. \u2013 3:00 p.m.\n\nFood Truck Lineup (Subject to Change, Alternates every other week): Los Tolucas taco truck, Hula Truck, Baby Brothers BBQ, Big Ed's Buzzard BBQ, We Sushi, 3 Brothers, Dil Se, Curry Up Now, Baba Kabob, Cluck It Up, Hongry Kong, Lobsta Truck, Drewski's, Grilled Cheese Bandits, Hela Gela, Swifty Sweets",
              "start_time": "2015-08-01T11:00:00-0700",
              "location": "4075 Evergreen Village Square, San Jose",
              "end_time": "2015-08-01T15:00:00-0700"
           },
           {
              "id": "1473614082953030",
              "cover": {
                 "cover_id": "1012103788809852",
                 "offset_x": 0,
                 "offset_y": 0,
                 "source": "https://scontent.xx.fbcdn.net/hphotos-xtf1/v/l/t1.0-9/s720x720/11742643_1012103788809852_7285968984666024747_n.jpg?oh=0a1d9b072fe440c634c36f983bb27939&oe=5619AE80",
                 "id": "1012103788809852"
              },
              "name": "Off the Grid: Novato \u0040 Vintage Oaks (Thursday Dinner)",
              "description": "Welcome to our northernmost location, OtG: Novato \u0040 Vintage Oaks! We'll be here to bring you delicious food truck dinners every Thursday from 5-9pm.\n\nLocation: 201 Vintage Way, Novato CA\nTime: Every Thursday, 5:00 p.m. to 9:00 p.m.",
              "start_time": "2015-03-30T17:00:00-0700",
              "location": "201 Vintage Way, Novato CA",
              "end_time": "2015-03-30T21:00:00-0700"
             }]
   
     create_event_models(added) 
     check_db()
     current_db_data = Event.objects.all()
     self.assertEqual(len(current_db_data), 2)
Example #2
0
def init_config():
    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s [%(module)10s] [%(levelname)5s] %(message)s')
    parser = argparse.ArgumentParser()
    config_file = "config.json"

    load = {}
    if os.path.isfile(config_file):
        with open(config_file) as data:
            load.update(json.load(data))

    parser.add_argument("-a",
                        "--auth_service",
                        help="Auth Service ('ptc' or 'google')",
                        default="ptc")
    parser.add_argument("-u", "--username", help="Username")
    parser.add_argument("-p", "--password", help="Password")
    parser.add_argument("-t",
                        "--delay",
                        help="rpc request interval",
                        default=10,
                        type=int)
    parser.add_argument("-l",
                        "--limit",
                        help="clusters to monitor",
                        default=100,
                        type=int)
    parser.add_argument("-d",
                        "--debug",
                        help="Debug Mode",
                        action='store_true',
                        default=0)
    config = parser.parse_args()

    for key in config.__dict__:
        if key in load and config.__dict__[key] == None:
            config.__dict__[key] = load[key]

    if config.debug:
        logging.getLogger("requests").setLevel(logging.DEBUG)
        logging.getLogger("pgoapi").setLevel(logging.DEBUG)
        logging.getLogger("rpc_api").setLevel(logging.DEBUG)
    else:
        logging.getLogger("requests").setLevel(logging.WARNING)
        logging.getLogger("pgoapi").setLevel(logging.WARNING)
        logging.getLogger("rpc_api").setLevel(logging.WARNING)

    if config.auth_service not in ['ptc', 'google']:
        log.error("Invalid Auth service specified! ('ptc' or 'google')")
        return None

    dbversion = check_db('db2.sqlite')
    if dbversion != VERSION:
        log.error('Database version mismatch! Expected {}, got {}...'.format(
            VERSION, dbversion))
        return

    return config
Example #3
0
def init_config():
    parser = argparse.ArgumentParser()     
    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(module)10s] [%(levelname)5s] %(message)s')

    load   = {}
    config_file = "config.json"
    if os.path.isfile(config_file):
        with open(config_file) as data:
            load.update(json.load(data))

    parser.add_argument("-a", "--auth_service", help="Auth Service ('ptc' or 'google')", default="ptc")
    parser.add_argument("-u", "--username", help="Username")
    parser.add_argument("-p", "--password", help="Password")
    parser.add_argument("-l", "--location", help="Location")
    parser.add_argument("-r", "--radius", help="area circle radius", type=int)
    parser.add_argument("-w", "--width", help="area square width", type=int)
    parser.add_argument("-f", "--dbfile", help="DB filename", default='db.sqlite')
    parser.add_argument("--level", help="cell level used for tiling", default=13, type=int)
    parser.add_argument("-t", "--delay", help="rpc request interval", default=10, type=int)
    parser.add_argument("-d", "--debug", help="Debug Mode", action='store_true', default=0)
    parser.add_argument("-n", "--test", help="Beta algorithm", action='store_true', default=0)        
    config = parser.parse_args()

    for key in config.__dict__:
        if key in load and config.__dict__[key] == None:
            config.__dict__[key] = load[key]

    if config.auth_service not in ['ptc', 'google']:
        log.error("Invalid Auth service specified! ('ptc' or 'google')")
        return None

    if config.debug:
        logging.getLogger("requests").setLevel(logging.DEBUG)
        logging.getLogger("pgoapi").setLevel(logging.DEBUG)
        logging.getLogger("rpc_api").setLevel(logging.DEBUG)
    else:
        logging.getLogger("requests").setLevel(logging.WARNING)
        logging.getLogger("pgoapi").setLevel(logging.WARNING)
        logging.getLogger("rpc_api").setLevel(logging.WARNING)
   
    dbversion = check_db(config.dbfile)     
    if dbversion != VERSION:
        log.error('Database version mismatch! Expected {}, got {}...'.format(VERSION,dbversion))
        return
    
    if config.location:
        from utils import get_pos_by_name
        lat, lng, alt = get_pos_by_name(config.location); del alt
        if config.radius:
            cells = cover_circle(lat, lng, config.radius, config.level)
        elif config.width:
            cells = cover_square(lat, lng, config.width, config.level)
        else: log.error('Area size not given!'); return
        log.info('Added %d cells to scan queue.' % init_db(cells, config.dbfile))
        del cells, lat, lng
    
    return config
Example #4
0
def eventsview(request):
    check_db()
    if len(Vendor.objects.all()) == 0:
        content = read_data("http://offthegridsf.com/vendors#food")
        vendors = parse_HTML(content)
        create_vendor_models(vendors)
    fb_data = read_data(facebookurl)
    if len(Event.objects.all()) > 0 and fb_data != "ERROR":
        event_data_ready = check_recent_fb_json(fb_data["data"])
        create_event_models(event_data_ready)
        establish_relation()
    elif fb_data != "ERROR":
        print "WERE here"
        next_parameter = fb_data["paging"]["cursors"]["after"]
        next_set = transform_url(facebookurl, next_parameter)
        second = read_data(next_set)
        fulldata = fb_data["data"] + second["data"]
        events = check_less_thirty(fulldata)
        create_event_models(events)
        establish_relation()
    event_list = Event.objects.all().order_by("-event_time")
    context_dict = {"events": event_list}
    return render(request, "GingerBites/events.html", context_dict)
Example #5
0
def eventview(request, event_name):
    check_db()
    event = Event.objects.all().filter(event_slug=event_name)
    vendor_list = event[0].vendor_set.all()
    context_dict = {"event": event[0], "vendors": vendor_list}
    return render(request, "GingerBites/event.html", context_dict)  
Example #6
0
def vendorview(request, vendor_name):
    check_db()
    vendor = Vendor.objects.all().filter(vendor_slug=vendor_name)
    v = vendor.annotate(count=Count("event"))
    context_dict = {"vendor": v[0]}
    return render(request, "GingerBites/vendor.html", context_dict)
Example #7
0
def vendorsview(request):
    check_db()
    order_appearance = Vendor.objects.annotate(appearances=Count("event")).order_by("-appearances")
    context_dict = {"vendors": order_appearance}
    return render(request, "GingerBites/vendors.html", context_dict)