def get_events(user): try: events = list() logger.info("Getting events from grpah api...") graph = facebook.GraphAPI(ACCESS_TOKEN) profile = graph.get_object(user) posts = graph.get_connections(profile['id'], 'events', fields='id,attending_count,\ cover,description,end_time,start_time,name,\ place,updated_time', since=sincet) # print(posts) while True: try: # Perform some action on each post in the collection we receive from # Facebook. for post in posts['data']: events.append(post) # Attempt to make a request to the next page of data, if it exists. posts = requests.get(posts['paging']['next']).json() except KeyError: # When there are no more pages (['paging']['next']), break from the # loop and end the script. break return events except Exception as e: logger.exception("Failure getting event data : {}".format(e))
def delete_event(Event_Id): try: FBEvents.objects.filter(Event_Id=Event_Id).delete() except Exception as e: logger.exception( 'delete_event: Passing to next line. Possibly because of no data returned by query: {}' .format(e))
def user_friendly_time(time_str): try: uf_time = datetime.datetime.strptime(time_str, '%Y-%m-%dT%H:%M:%S%z') format = "%a %b %d %H:%M:%S %Y" return uf_time.strftime(format) except Exception as err: logger.exception( "Could not convert to user_friendly_time {}".format(err)) return time_str
def fb_event_cron(): """Gets Events from facebook and run cron :return: list of events :rtype: list """ try: return get_fb_events(PAGE_IDS) except Exception as err: logger.exception("Error getting FB events :{}".format(err))
def get_existing_events(): dpost_id = list() try: dist_id = FBLocation.objects.all() for i in dist_id: dpost_id.append(i.Name) return dpost_id except Exception as e: logger.exception( 'Passing to next item. Possibly because of no data returned by query: {}' .format(e))
def post_events(location_name, post_name, picture, description, start_time, end_time, event_link, place): graph = facebook.GraphAPI(ACCESS_TOKEN) graph_tiin = facebook.GraphAPI(P_ACCESS_TOKEN_TIIN) thetangoindia_fb_grp = "1743007585978030" # thetangoindia FB group # thetangoindia_fb_page = "334065376933472" #thetangoindia FB Page # tangoinindia = "1542666775825337" tango_in_india = "428875644194564" thetangoindia = 'http://thetangoindia.in/Tango-Events/' uf_start_time = user_friendly_time(start_time) msg = "{} - {} {} \nStart Time: {} \n\nVisit {} to see events across India.\n\n Details: {}".format( post_name, location_name, place, uf_start_time, thetangoindia, description) # post = requests.post("{}/feed?message={}".format(id, msg)) try: graph_tiin.put_object(parent_object=tango_in_india, connection_name='feed', message=msg, link=event_link) logger.warning( "Posted a new event in tango_in_india: {}".format(event_link)) except Exception as e: logger.exception( "Exception while posting new event to tango_in_india FB page: {}, {}, {}" .format(location_name, event_link, e)) try: graph.put_object(parent_object=thetangoindia_fb_grp, connection_name='feed', message=msg, link=event_link) logger.warning( "Posted a new event in tango_in_india_fb_group: {}".format( event_link)) except Exception as e: logger.exception( "Exception while posting new event to thetangoindia_fb_grp: {}, {}, {}" .format(location_name, event_link, e))
from config_settings import PROJECT_DIR, PROJECT_BASE_DIR, SITE_PKG_PATH, logger sys.path.append(SITE_PKG_PATH) sys.path.append(PROJECT_DIR) sys.path.append(os.path.join(PROJECT_BASE_DIR, 't/tango/src/tango/settings/')) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "production") from django.core.wsgi import get_wsgi_application application = get_wsgi_application() from django.conf import settings # Wrap werkzeug debugger if DEBUG is on if settings.DEBUG: try: import django.views.debug import six from werkzeug.debug import DebuggedApplication def null_technical_500_response(request, exc_type, exc_value, tb): six.reraise(exc_type, exc_value, tb) django.views.debug.technical_500_response = null_technical_500_response application = DebuggedApplication(application, evalex=True) except ImportError: logger.exception("Exception while running on DEBUG mode.") except Exception as e: logger.exception("Exception while running on DEBUG mode: {}".format(e))