Example #1
0
    def test_check_recent_fb_json(self):
        facebookdata = [{
                 "id": "5",
                 "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-05T17:00:00-0700",
                 "location": "UC Berkeley",
                  },
                {
                 "id": "75",
                 "name": "Off the Grid: North Oakland (Friday Dinner)",
                 "description": "Every Tuesday 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-04T17:00:00-0700",
                 "location": "Bart Station, 1750 Sacramento Street, Berkeley CA"
                },
                {
                 "id": "72",
                 "name": "Off the Grid: North San Franciso (Monday Dinner)",
                 "description": "Every Monday 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-01T17:00:00-0700",
                 "location": " Mall, 22 Donner Street, SF CA"
                }]

        create_event_models([{
             "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: 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": "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: 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-07-22T17:00:00-0700",
             "location": " North Berkeley Bart Station, 1750 Sacramento Street, Berkeley CA",
             "end_time": "2015-07-22T21:00:00-0700"
          }
        ]) 

        newestdata = check_recent_fb_json(facebookdata)         
        self.assertEqual(len(newestdata), 2)
Example #2
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)