Пример #1
0
def get_data():
    try:
        request_data = \
            {
                "ip": request.remote_addr,
                "callback": request.args.get("callback", False),
                "tags": request.args.get("tags", False)
            }

        #init data provider
        data_provider = DataProvider(request_data)
        #get data from provider
        response_data = data_provider.get_data()
        #make json
        response_json = json.dumps(response_data)

        if request_data["callback"]:
            response_json = "{0}({1})".format(request_data["callback"], json.dumps(response_data))

        return Response(response=response_json, status=200, mimetype="application/json",
                        headers={"P3P": "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD "
                                        "IVAi IVDi CONi HIS OUR IND CNT\""})
    except Exception, e:
        logger.exception(e)
        response = Response(response=None, status=200)
        return response
Пример #2
0
def update_links():
    results = graph.cypher.stream("match (s:Show)-->(se:Season)-->(e:Episode) return s.name,se.no,e.epnum,id(e) as eid")

    for record in results:
        search = record['s.name'] + ' s' + str(record['e.epnum']).zfill(2) + 'e' + str(record['se.no']).zfill(2)

        # links
        search_numbers = [3552639851, 8556419051, 2649486255, 7079685853, 8416818254, 1870757059, 1731156253,
                          4545021852, 6021755051, 8975221455]

        for n in search_numbers:
            try:
                links_from_google = requests.get(
                    'https://www.googleapis.com/customsearch/v1element?key=AIzaSyCVAXiUzRYsML1Pv6RwSG1gunmMikTzQqY&rsz=small&num=10&hl=en&prettyPrint=false&source=gcsc&gss=.com&sig=cb6ef4de1f03dde8c26c6d526f8a1f35&cx=partner-pub-2526982841387487:{1}'
                    '&q={0}&googlehost=www.google.com&oq={0}'.format(search, n))

                dict_from_google = json.loads(links_from_google.text)
                for result in dict_from_google['results']:

                    link_node = graph.merge_one("Link", 'url', result['url'])
                    link_node['host'] = result.get('visibleUrl', 'unknown')
                    link_node.push()

                    episode_node = graph.node(record['eid'])
                    link_episode = Relationship(episode_node, "has", link_node)
                    graph.create(link_episode)

            except Exception, err:
                logger.exception("error grom google part")
Пример #3
0
def get_data():
    try:
        request_data = \
            {
                "ip": request.remote_addr,
                "callback": request.args.get("callback", False),
                "tags": request.args.get("tags", False)
            }

        #init data provider
        data_provider = DataProvider(request_data)
        #get data from provider
        response_data = data_provider.get_data()
        #make json
        response_json = json.dumps(response_data)

        if request_data["callback"]:
            response_json = "{0}({1})".format(request_data["callback"], json.dumps(response_data))

        return Response(response=response_json, status=200, mimetype="application/json",
                        headers={"P3P": "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD "
                                        "IVAi IVDi CONi HIS OUR IND CNT\""})
    except Exception, e:
        logger.exception(e)
        response = Response(response=None, status=200)
        return response
Пример #4
0
 def get_network_data_table():
     table_name = 'network_data'
     try:
         table = Table(table_name, MetaData(bind=MySqlFactory.stats_server), autoload=True)
     except Exception:
         logger.exception("there is no network_data table. please provide one!!!")
     return table
Пример #5
0
    def run(self):
        try:
            start_time = datetime.utcnow()
            logger.info("+ Running services")

            provider = NadavProvider()
            provider.run()

            logger.info("- Running services, elapsed time:[{0}]".format(datetime.utcnow() - start_time))
        except Exception, e:
            logger.exception(e)
Пример #6
0
def web_socket_echo(ws):
    try:
        logger.warning("/websocket")
        while True:
            msg = ws.receive()
            if msg is not None:
                ws.send(msg)
            else:
                return
    except Exception, e:
        logger.exception(e)
        response = Response(response=None, status=200)
        return response
Пример #7
0
def web_socket_echo(ws):
    try:
        logger.warning("/websocket")
        while True:
            msg = ws.receive()
            if msg is not None:
                ws.send(msg)
            else:
                return
    except Exception, e:
        logger.exception(e)
        response = Response(response=None, status=200)
        return response
Пример #8
0
def vc_rog_widget_joystick():
    try:
        if request.method == 'GET':
            request_data = \
                {
                    "method": "GET",
                    "ip": request.remote_addr,
                    "callback": request.args.get("callback", False),
                    "tags": request.args.get("tags", False),
                }
        else:
            request_data = \
                {
                    "method": "POST",
                    "ip": request.remote_addr,
                    "callback": request.args.get("callback", False),
                    "last": request.form.get('last', 'None'),
                    "name": request.form.get('name', 'None'),
                    "postRequestData": request.form
                }

        #init data provider
        #data_provider = GeoIpProvider(request_data)
        #get data from provider
        #response_data = data_provider.get_data()
        #make json
        response_json = json.dumps({"a": "a"})

        if request_data["callback"]:
            response_json = "{0}({1})".format(request_data["callback"],
                                              json.dumps(response_data))

        return Response(response=response_json,
                        status=200,
                        mimetype="application/json",
                        headers={
                            "P3P":
                            "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD "
                            "IVAi IVDi CONi HIS OUR IND CNT\""
                        })
    except Exception, e:
        logger.exception(e)
        response = Response(response=None, status=200)
        return response
Пример #9
0
    def get_links_for_episode(self, show, season, episode):
        search = show + ' s' + str(season).zfill(2) + 'e' + str(episode).zfill(2)

        search_numbers = [
            3552639851]  # , 8556419051]; #, 2649486255, 7079685853, 8416818254, 1870757059, 1731156253,4545021852, 6021755051, 8975221455]

        links = []
        return links
        for n in search_numbers:
            try:
                links_from_google = requests.get(
                    'https://www.googleapis.com/customsearch/v1element?key=AIzaSyCVAXiUzRYsML1Pv6RwSG1gunmMikTzQqY&rsz=small&num=10&hl=en&prettyPrint=false&source=gcsc&gss=.com&sig=cb6ef4de1f03dde8c26c6d526f8a1f35&cx=partner-pub-2526982841387487:{1}'
                    '&q={0}&googlehost=www.google.com&oq={0}'.format(search, n))

                dict_from_google = json.loads(links_from_google.text)
                for result in dict_from_google['results']:
                    links.append({
                        "url": result['url'],
                        "host": result.get('visibleUrl', 'unknown')
                    })
            except Exception, err:
                logger.exception("error grom google part")
Пример #10
0
def update_info_and_links():
    print 'updating show info'
    authenticate("localhost:7474", "neo4j", "1234")
    graph = Graph(GRAPH_CONNECTION_STRNIG)

    results = graph.cypher.stream("match (s:Show) return id(s) as eid,s.id")
    start_id = 0
    for record in results:
        if int(record['s.id']) < start_id:
            continue

        node_show = graph.node(record['eid'])

        result_dict = {}

        success = True
        while success:
            try:
                show_info_e_list = requests.get(
                    'http://services.tvrage.com/feeds/full_show_info.php?sid={0}'.format(node_show['id']))
                result_dict = xmltodict.parse(show_info_e_list.text)

                omdb_show_info = requests.get(
                    'http://www.omdbapi.com/?t={0}&y=&plot=full&r=json'.format(node_show['name']))
                dict_omdb_show_info = json.loads(omdb_show_info.text)
                if dict_omdb_show_info['Response'] == 'True':
                    for key, value in dict_omdb_show_info.iteritems():
                        node_show[key] = value
                success = False
            except ValueError as e:
                logger.exception("Value error")
                continue
            except Exception as e:
                logger.exception("Some network issue: will try again")
                success = True

        print str(node_show['name'])
        # info

        node_show['started'] = result_dict['Show'].get('started', None)
        node_show['ended'] = result_dict['Show'].get('ended', None)
        node_show['image'] = result_dict['Show'].get('image', None)
        node_show['status'] = result_dict['Show'].get('status', None)
        node_show.push()

        #Country
        from_country = result_dict['Show'].get('origin_country', 'unknown')

        node_country = graph.merge_one("Country", 'country', from_country)
        node_country.push()

        show_from_country = Relationship(node_show, "from", node_country)
        graph.create(show_from_country)


        #Genres
        if result_dict['Show'].get('genres', None) is not None:
            genre_list = []
            if type(result_dict['Show']['genres']['genre']) is list:
                genre_list = result_dict['Show']['genres']['genre']
            else:
                genre_list.append(result_dict['Show']['genres']['genre'])

            for genre in genre_list:
                node_genre = graph.merge_one("Genre", 'name', genre)
                node_genre.push()

                show_of_genre = Relationship(node_show, "of genre", node_genre)
                graph.create(show_of_genre)
        """
        try:
            print node_show['started']
            a = node_show['started'].split("/")
            if int(a[len(a)-1]) < 2000:
                continue
        except Exception:
            continue
        """


        #Seasons
        season_list = []
        if result_dict['Show'].get('Episodelist', None) is None:
            continue
        if type(result_dict['Show']['Episodelist']['Season']) is list:
            season_list = result_dict['Show']['Episodelist']['Season']
        else:
            season_list.append(result_dict['Show']['Episodelist']['Season'])

        for season in season_list:
            node_season = Node.cast('Season', {'no': season['@no']})
            graph.create(node_season)

            show_season = Relationship(node_show, "has", node_season)
            graph.create(show_season)

            #Episodes
            episode_list = []
            if type(season['episode']) is list:
                episode_list = season['episode']
            else:
                episode_list.append(season['episode'])
            count = 1
            for episode in episode_list:
                node_episode = Node.cast('Episode', {
                    'airdate': episode.get('airdate', None),
                    'epnum': count,
                    'screencap': episode.get('screencap', None),
                    'title': episode.get('title', None)
                })
                graph.create(node_episode)

                success = True
                while success:
                    try:
                        omdb_episode_info = requests.get('http://www.omdbapi.com/?t={0}&Season={1}&Episode={2}'
                                                         .format(node_show['name'],
                                                                 node_season['no'],
                                                                 node_episode['epnum']))
                        dict_omdb_episode_info = json.loads(omdb_episode_info.text)
                        if dict_omdb_episode_info['Response'] == 'True':
                            for key, value in dict_omdb_episode_info.iteritems():
                                node_episode[key] = value
                        node_episode.push()

                        success = False
                    except ValueError as e:
                        logger.exception("Value error")
                        continue
                    except Exception as e:
                        logger.exception("Some network issue: will try again")
                        success = True

                try:

                    search = node_show['name'] + ' s' + str(node_season['no']).zfill(2) + 'e' + str(node_episode['epnum']).zfill(2)

                    print search
                    #links
                    search_numbers = [3552639851, 8556419051, 2649486255, 7079685853, 8416818254, 1870757059,
                                      1731156253, 4545021852, 6021755051, 8975221455]

                    for n in search_numbers:
                        links_from_google = requests.get(
                            'https://www.googleapis.com/customsearch/v1element?key=AIzaSyCVAXiUzRYsML1Pv6RwSG1gunmMikTzQqY&rsz=small&num=10&hl=en&prettyPrint=false&source=gcsc&gss=.com&sig=cb6ef4de1f03dde8c26c6d526f8a1f35&cx=partner-pub-2526982841387487:{1}'
                            '&q={0}&googlehost=www.google.com&oq={0}'.format(search, n))

                        dict_from_google = json.loads(links_from_google.text)
                        for result in dict_from_google['results']:
                            node_link = Node.cast('Link', {
                                'host': result.get('visibleUrl', None),
                                'url': result['url']
                            })
                            graph.create(node_link)
                            link_episode = Relationship(node_episode, "has", node_link)
                            graph.create(link_episode)
                except Exception, err:
                    logger.exception("error grom google part")

                show_episode = Relationship(show_season, "has", node_episode)
                graph.create(show_episode)
                count = count + 1
Пример #11
0
def create_shows():
    """
    fills DB with all the shows
    :return:
    """

    for page_num in range(0, 10, 1):
        r = requests.get('http://api.tvmaze.com/shows?page={0}'.format(page_num))
        shows = json.loads(r.text)

        for show in shows:
            show_node = graph.merge_one("Show", 'id', show['id'])

            show_node['url'] = show['url']
            show_node['name'] = show['name']
            show_node['type'] = show['type']
            show_node['status'] = show['status']
            show_node['runtime'] = show['runtime']
            show_node['premiered'] = show['premiered']
            show_node['weight'] = show['weight']

            if show['rating'] is not None:
                show_node['rating'] = show['rating']['average']

            show_node['summary'] = show['summary']

            show_node['img_medium'] = show['image'].get('medium', None)
            show_node['img_original'] = show['image'].get('original', None)
            show_node.push()

            for genre in show.get('genres', []):
                genre_node = graph.merge_one("Genre", 'genre', genre)
                show_of_genre = Relationship(show_node, "of genre", genre_node)
                graph.create_unique(show_of_genre)

            if show['webChannel'] is not None:
                webchannel_node = graph.merge_one("WebChannel", 'id', show['webChannel']['id'])
                webchannel_node['name'] = show['webChannel']['name']
                webchannel_node.push()

                show_of_webchannel = Relationship(show_node, "from", webchannel_node)
                graph.create_unique(show_of_webchannel)

                if show['webChannel']['country'] is not None:
                    country_node = graph.merge_one("Country", 'code', show['webChannel']['country']['code'])
                    country_node['name'] = show['webChannel']['country']['name']
                    country_node['timezone'] = show['webChannel']['country']['timezone']
                    country_node.push()

                    webchannel_from_country = Relationship(webchannel_node, "from", country_node)
                    graph.create_unique(webchannel_from_country)

            if show['network'] is not None:
                network_node = graph.merge_one("Network", 'id', show['network']['id'])
                network_node['name'] = show['network']['name']
                network_node.push()

                show_of_network = Relationship(show_node, "from", network_node)
                graph.create_unique(show_of_network)

                country_node = graph.merge_one("Country", 'code', show['network']['country']['code'])
                country_node['name'] = show['network']['country']['name']
                country_node['timezone'] = show['network']['country']['timezone']
                country_node.push()

                network_from_country = Relationship(network_node, "from", country_node)
                graph.create_unique(network_from_country)

            r1 = requests.get('http://api.tvmaze.com/shows/{0}/episodes'.format(show['id']))
            episodes = json.loads(r1.text)

            for episode in episodes:
                episode_node = graph.merge_one("Episode", 'id', episode['id'])
                episode_node['name'] = episode['name']
                episode_node['season'] = episode['season']
                episode_node['number'] = episode['number']
                episode_node['airdate'] = episode['airdate']
                episode_node['airtime'] = episode['airtime']
                episode_node['airstamp'] = episode['airstamp']
                episode_node['runtime'] = episode['runtime']
                episode_node['summary'] = episode['summary']

                if episode['image'] is not None:
                    episode_node['img_medium'] = episode['image'].get('medium', None)
                    episode_node['img_original'] = episode['image'].get('original', None)

                episode_node.push()

                show_has_episode = Relationship(show_node, "has", episode_node)
                graph.create_unique(show_has_episode)

                search = show['name'] + ' s' + str(episode['season']).zfill(2) + 'e' + str(episode['number']).zfill(2)

                # links
                search_numbers = [3552639851]#, 8556419051]; #, 2649486255, 7079685853, 8416818254, 1870757059, 1731156253,4545021852, 6021755051, 8975221455]

                for n in search_numbers:
                    try:
                        links_from_google = requests.get(
                            'https://www.googleapis.com/customsearch/v1element?key=AIzaSyCVAXiUzRYsML1Pv6RwSG1gunmMikTzQqY&rsz=small&num=10&hl=en&prettyPrint=false&source=gcsc&gss=.com&sig=cb6ef4de1f03dde8c26c6d526f8a1f35&cx=partner-pub-2526982841387487:{1}'
                            '&q={0}&googlehost=www.google.com&oq={0}'.format(search, n))

                        dict_from_google = json.loads(links_from_google.text)
                        for result in dict_from_google['results']:

                            link_node = graph.merge_one("Link", 'url', result['url'])
                            link_node['host'] = result.get('visibleUrl', 'unknown')
                            link_node.push()

                            link_has_episode = Relationship(episode_node, "has", link_node)
                            graph.create(link_has_episode)

                    except Exception, err:
                        logger.exception("error grom google part")
Пример #12
0
def update_show_info_old():
    print 'updating show info'
    authenticate("localhost:7474", "neo4j", "1234")
    graph = Graph(GRAPH_CONNECTION_STRNIG)

    results = graph.cypher.stream("match (s:Show) return id(s) as eid,s.id")
    start_id = 764
    for record in results:
        if int(record['s.id']) < start_id:
            continue

        node_show = graph.node(record['eid'])

        result_dict = {}

        success = True
        while success:
            try:
                show_info_e_list = requests.get(
                    'http://services.tvrage.com/feeds/full_show_info.php?sid={0}'.format(node_show['id']))
                result_dict = xmltodict.parse(show_info_e_list.text)

                omdb_show_info = requests.get(
                    'http://www.omdbapi.com/?t={0}&y=&plot=full&r=json'.format(node_show['name']))
                dict_omdb_show_info = json.loads(omdb_show_info.text)
                if dict_omdb_show_info['Response'] == 'True':
                    for key, value in dict_omdb_show_info.iteritems():
                        node_show[key] = value
                success = False
            except ValueError as e:
                logger.exception("Value Error")
                continue
            except Exception as e:
                logger.exception("Some network issue, will try again")
                success = True

        print str(node_show['name'])
        # info

        node_show['started'] = result_dict['Show'].get('started', None)
        node_show['ended'] = result_dict['Show'].get('ended', None)
        node_show['image'] = result_dict['Show'].get('image', None)
        node_show['status'] = result_dict['Show'].get('status', None)
        node_show.push()

        #Country
        from_country = result_dict['Show'].get('origin_country', 'unknown')

        node_country = graph.merge_one("Country", 'country', from_country)
        node_country.push()

        show_from_country = Relationship(node_show, "from", node_country)
        graph.create(show_from_country)


        #Genres
        if result_dict['Show'].get('genres', None) is not None:
            genre_list = []
            if type(result_dict['Show']['genres']['genre']) is list:
                genre_list = result_dict['Show']['genres']['genre']
            else:
                genre_list.append(result_dict['Show']['genres']['genre'])

            for genre in genre_list:
                node_genre = graph.merge_one("Genre", 'name', genre)
                node_genre.push()

                show_of_genre = Relationship(node_show, "of genre", node_genre)
                graph.create(show_of_genre)

        """try:
            print node_show['started']
            a = node_show['started'].split("/")
            if int(a[len(a)-1]) < 2000:
                continue
        except Exception:
            continue
        """

        #Seasons
        season_list = []
        if result_dict['Show'].get('Episodelist', None) is None:
            continue
        if type(result_dict['Show']['Episodelist']['Season']) is list:
            season_list = result_dict['Show']['Episodelist']['Season']
        else:
            season_list.append(result_dict['Show']['Episodelist']['Season'])

        for season in season_list:
            node_season = Node.cast('Season', {'no': season['@no']})
            graph.create(node_season)

            show_season = Relationship(node_show, "has", node_season)
            graph.create(show_season)

            #Episodes
            episode_list = []
            if type(season['episode']) is list:
                episode_list = season['episode']
            else:
                episode_list.append(season['episode'])
            count = 1
            for episode in episode_list:
                node_episode = Node.cast('Episode', {
                    'airdate': episode.get('airdate', None),
                    'epnum': count,
                    'screencap': episode.get('screencap', None),
                    'title': episode.get('title', None)
                })
                graph.create(node_episode)

                success = True
                while success:
                    try:
                        omdb_episode_info = requests.get('http://www.omdbapi.com/?t={0}&Season={1}&Episode={2}'
                                                         .format(node_show['name'],
                                                                 node_season['no'],
                                                                 node_episode['epnum']))
                        dict_omdb_episode_info = json.loads(omdb_episode_info.text)
                        if dict_omdb_episode_info['Response'] == 'True':
                            for key, value in dict_omdb_episode_info.iteritems():
                                node_episode[key] = value
                        node_episode.push()
                        success = False
                    except ValueError as e:
                        logger.exception("Value error")
                        continue
                    except Exception as e:
                        logger.exception("network issue: wil try again")
                        success = True

                show_episode = Relationship(show_season, "has", node_episode)
                graph.create(show_episode)
                count = count + 1

    print 'end updating show info'
Пример #13
0
def update_show_info(show_node):
    """
    collect the basic information about the show
    :param show_id:
    :return:
    """
    result_dict = {}
    try:
        # data source (tvrage)
        show_info_e_list = requests.get(
            'http://services.tvrage.com/feeds/full_show_info.php?sid={0}'.format(show_node['id']))
        result_dict = xmltodict.parse(show_info_e_list.text)

        show_node['started'] = result_dict['Show'].get('started', None)
        show_node['ended'] = result_dict['Show'].get('ended', None)
        show_node['image'] = result_dict['Show'].get('image', None)
        show_node['status'] = result_dict['Show'].get('status', None)

        # data source (omdbapi)
        omdb_show_info = requests.get(
            'http://www.omdbapi.com/?t={0}&y=&plot=full&r=json'.format(show_node['name']))
        dict_omdb_show_info = json.loads(omdb_show_info.text)
        if dict_omdb_show_info['Response'] == 'True':
            for key, value in dict_omdb_show_info.iteritems():
                show_node[key] = value
        show_node.push()

    except ValueError as e:
        logger.exception("Value Error")
        return
    except Exception as e:
        logger.exception("Some network issue, will try again")

    # Country
    show_to_country(show_node, result_dict['Show'].get('origin_country', 'unknown'))

    #Genres
    if result_dict['Show'].get('genres', None) is not None:
        genre_list = []
        if type(result_dict['Show']['genres']['genre']) is list:
            genre_list = result_dict['Show']['genres']['genre']
        else:
            genre_list.append(result_dict['Show']['genres']['genre'])

        for genre in genre_list:
            show_to_genre(show_node, genre)

    #Seasons
    season_list = []
    if result_dict['Show'].get('Episodelist', None) is None:
        # there are no seasons for this show
        return

    if type(result_dict['Show']['Episodelist']['Season']) is list:
        season_list = result_dict['Show']['Episodelist']['Season']
    else:
        season_list.append(result_dict['Show']['Episodelist']['Season'])

    for season in season_list:
        season_node = get_season_for_show(show_node, season['@no'])

        #Episodes
        episode_list = []
        if type(season['episode']) is list:
            episode_list = season['episode']
        else:
            episode_list.append(season['episode'])

        count = 1
        for episode in episode_list:
            episode_basic_info = {
                'airdate': episode.get('airdate', None),
                'epnum': count,
                'screencap': episode.get('screencap', None),
                'title': episode.get('title', None)
            }
            episode_node = get_episode_for_season_show(show_node, season_node ,episode_basic_info)

            # Add episode info
            try:
                omdb_episode_info = requests.get('http://www.omdbapi.com/?t={0}&Season={1}&Episode={2}'
                                                 .format(show_node['name'],
                                                         season_node['no'],
                                                         episode_node['epnum']))

                dict_omdb_episode_info = json.loads(omdb_episode_info.text)

                if dict_omdb_episode_info['Response'] == 'True':
                    for key, value in dict_omdb_episode_info.iteritems():
                        episode_node[key] = value
                episode_node.push()
            except ValueError as e:
                logger.exception("Value error")
            except Exception as e:
                logger.exception("network issue: wil try again")
                success = True

            show_episode = Relationship(season_node, "has", episode_node)
            graph.create(show_episode)
            count = count + 1
Пример #14
0
def views(name):
    try:
        return render_template("/views/" + name)
    except Exception, e:
        logger.exception(e)
        response = Response(response=None, status=200, mimetype="text/html")
Пример #15
0
    def _update_show(self, show_id):
        # get the node from the graph
        node_show = self.graph.node(show_id)
        if node_show['updated'] == True:
            return

        result_dict = {}
        try:
            show_info_e_list = requests.get(
                'http://services.tvrage.com/feeds/full_show_info.php?sid={0}'.format(node_show['id']))
            result_dict = xmltodict.parse(show_info_e_list.text)

            omdb_show_info = requests.get(
                'http://www.omdbapi.com/?t={0}&y=&plot=full&r=json'.format(node_show['name']))
            dict_omdb_show_info = json.loads(omdb_show_info.text)
            if dict_omdb_show_info['Response'] == 'True':
                for key, value in dict_omdb_show_info.iteritems():
                    node_show[key] = value
            success = False
        except ValueError as e:
            logger.exception("Value Error")
            return
        except Exception as e:
            logger.exception("Some network issue, will try again")
            return

        # add the new extracted data to the show
        node_show['started'] = result_dict['Show'].get('started', None)
        node_show['ended'] = result_dict['Show'].get('ended', None)
        node_show['image'] = result_dict['Show'].get('image', None)
        node_show['status'] = result_dict['Show'].get('status', None)
        node_show.push()

        # Country
        from_country = result_dict['Show'].get('origin_country', 'unknown')
        node_country = self.graph.merge_one("Country", 'country', from_country)
        node_country.push()

        # add the relation to the graph
        show_from_country = Relationship(node_show, "from", node_country)
        self.graph.create(show_from_country)

        # Genres
        if result_dict['Show'].get('genres', None) is not None:
            genre_list = []
            if type(result_dict['Show']['genres']['genre']) is list:
                genre_list = result_dict['Show']['genres']['genre']
            else:
                genre_list.append(result_dict['Show']['genres']['genre'])

            for genre in genre_list:
                # create the genre node
                node_genre = self.graph.merge_one("Genre", 'name', genre)
                node_genre.push()

                # add the Genre relation to the graph
                show_of_genre = Relationship(node_show, "of genre", node_genre)
                self.graph.create(show_of_genre)

        # Seasons
        season_list = []
        if result_dict['Show'].get('Episodelist', None) is None:
            return
        if type(result_dict['Show']['Episodelist']['Season']) is list:
            season_list = result_dict['Show']['Episodelist']['Season']
        else:
            season_list.append(result_dict['Show']['Episodelist']['Season'])

        for season in season_list:
            # create node for season
            node_season = Node.cast('Season', {'no': season['@no']})
            self.graph.create(node_season)

            # create the relation n the graph
            show_season = Relationship(node_show, "has", node_season)
            self.graph.create(show_season)

            # Episodes
            episode_list = []
            if type(season['episode']) is list:
                episode_list = season['episode']
            else:
                episode_list.append(season['episode'])

            count = 1
            for episode in episode_list:
                # create a node for episode
                node_episode = Node.cast('Episode', {
                    'airdate': episode.get('airdate', None),
                    'epnum': count,
                    'screencap': episode.get('screencap', None),
                    'title': episode.get('title', None)
                })
                self.graph.create(node_episode)

                # add relation to the graph
                show_episode = Relationship(show_season, "has", node_episode)
                self.graph.create(show_episode)


                # Episode info
                try:
                    omdb_episode_info = requests.get('http://www.omdbapi.com/?t={0}&Season={1}&Episode={2}'
                                                     .format(node_show['name'],
                                                             node_season['no'],
                                                             node_episode['epnum']))
                    dict_omdb_episode_info = json.loads(omdb_episode_info.text)
                    if dict_omdb_episode_info['Response'] == 'True':
                        for key, value in dict_omdb_episode_info.iteritems():
                            node_episode[key] = value
                    node_episode.push()
                except ValueError as e:
                    logger.exception("Value error")

                except Exception as e:
                    logger.exception("network issue: wil try again")

                # links
                try:
                    search = node_show['name'] + ' s' + str(node_season['no']).zfill(2) + 'e' + str(
                        node_episode['epnum']).zfill(2)

                    # links
                    search_numbers = [3552639851, 8556419051, 2649486255, 7079685853, 8416818254, 1870757059,
                                      1731156253, 4545021852, 6021755051, 8975221455]

                    for n in search_numbers:
                        links_from_google = requests.get(
                            'https://www.googleapis.com/customsearch/v1element?key=AIzaSyCVAXiUzRYsML1Pv6RwSG1gunmMikTzQqY&rsz=small&num=10&hl=en&prettyPrint=false&source=gcsc&gss=.com&sig=cb6ef4de1f03dde8c26c6d526f8a1f35&cx=partner-pub-2526982841387487:{1}'
                            '&q={0}&googlehost=www.google.com&oq={0}'.format(search, n))

                        dict_from_google = json.loads(links_from_google.text)
                        for result in dict_from_google['results']:
                            # create node for link
                            node_link = Node.cast('Link', {
                                'host': result.get('visibleUrl', None),
                                'url': result['url']
                            })
                            self.graph.create(node_link)

                            # create the relation in the graph
                            link_episode = Relationship(node_episode, "has", node_link)
                            self.graph.create(link_episode)
                except Exception, err:
                    logger.exception("error grom google part")
                count = count + 1
Пример #16
0
def index():
    """
    :return: a widget

    @callback - JSONP method name, make ? as default
    @widget - [button,cmd,depth,graph,joystick,keypad,led,log,rgb], log is the default widget
    @ros_host_ip - the ip of the ROS host machine - default is the web server IP
    @ros_host_port - the IP of the ROS machine, default is 9090
    @topic - the topic to publish/subscribe to
    @messagetype - the messagetype of the topic
    @name - the name of the widget
    @freq - the freq of the continues CMD to be sent to ROS
    """
    try:
        if request.method == 'GET':
            request_data = \
                {
                    "method": "GET",
                    "ip": request.remote_addr,
                    "callback": request.args.get("callback", False),
                    "ros_host_ip": request.args.get("ros_host_ip", "document.location.hostname"),
                    "ros_host_port": request.args.get("ros_host_port", "9090"),
                    "widget": request.args.get("widget", "log"),
                    "topic": request.args.get("topic", "/turtle1/cmd_vel"),
                    "messagetype": request.args.get("messagetype", "geometry_msgs/Twist"),
                    "name": request.args.get("name", "Simulator"),
                    "freq": request.args.get("freq", 1),
                }
        else:
            request_data = \
                {
                    "method": "POST",
                    "ip": request.remote_addr,
                    "callback": request.form.get("callback", False),
                    "postRequestData": request.form,
                    "ros_host_ip": request.form.get("ros_host_ip", "document.location.host"),
                    "widget": request.form.get("widget", "log"),
                    "topic": request.form.get("topic", "/turtle1/cmd_vel"),
                    "messagetype": request.form.get("messagetype", "geometry_msgs/Twist"),
                    "name": request.form.get("name", "S'imulator"),
                    "freq": request.form.get("freq", 1),
                }

        response_json = render_template("widgets/widget_ros_" +
                                        request_data["widget"] + ".html",
                                        data=request_data)

        if request_data["callback"]:  #JSONP
            response_json = "{0}({1})".format(
                request_data["callback"], json.dumps({"html": response_json}))
            return Response(response=response_json,
                            status=200,
                            mimetype="application/json",
                            headers={
                                "P3P":
                                "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD "
                                "IVAi IVDi CONi HIS OUR IND CNT\""
                            })
        else:  #NOT JSONP
            return response_json
    except Exception, e:
        logger.exception(e)
        response = Response(response=None, status=200)
        return response