def custom_google_search(self, search_string, index=1):
        keys = ["AIzaSyDM_PtVl-yhPmhgft6Si02vMJmOCatFK_w", "AIzaSyD9ufY0LcUPB8UO4RA4FVB8rJdZC12pKKc"]
        _id = "000167123881013238899:uys_fzjgaby"
        for i in range(0, 2):
            try:
                service = build("customsearch", "v1",
                                developerKey=keys[i])
                res_json = service.cse().list(
                    q=search_string,
                    cx=_id,
                    start=index
                ).execute()
                break
            except HttpError:
                continue
        else:
            logging.error("Quota ended")
            return []

        urls = []
        logging.info("custom google search result: " + str(res_json))
        try:
            for i in res_json['items']:
                urls.append(i['link'])
            logging.info("Urls: {urls}".format(urls=str(urls)))
            return urls
        except KeyError:
            return []
예제 #2
0
    def get_service(self, promptForAuth=False, launchBrowser=False):
        if self.service is None or self.token_expired:
            if self.http is None:
                self.http = httplib2.Http()
            self.auth(promptForAuth, launchBrowser)
            self.service =  build('drive', 'v2', http=self.http)

        return self.service
    def get(self):
        credentials = GoogleCredentials.get_application_default()
        bigquery = build('bigquery', 'v2', credentials=credentials)

        logging.info("Iterating over bucket...")
        entries = gcs.listbucket('/td-datastore-to-bigquery')

        most_recent_article = None
        most_recent_user = None

        for entry in entries:
            if "Article.backup_info" in entry.filename:
                if most_recent_article is None:
                    most_recent_article = entry
                elif entry.st_ctime > most_recent_article.st_ctime:
                    most_recent_article = entry

            if "User.backup_info" in entry.filename:
                if most_recent_user is None:
                    most_recent_user = entry
                elif entry.st_ctime > most_recent_user.st_ctime:
                    most_recent_user = entry

        logging.info('gs:/{}'.format(most_recent_article.filename))

        job_data = {
            'jobReference': {
                'projectId': project_id,
                'job_id': str(uuid.uuid4())
            },
            'configuration': {
                'load': {
                    'sourceUris': ['gs:/{}'.format(most_recent_user.filename)],
                    'sourceFormat': 'DATASTORE_BACKUP',
                    'destinationTable': {
                        'projectId': project_id,
                        'datasetId': dataset_id,
                        'tableId': table_name
                    }
                }
            }
        }

        response = bigquery.jobs().insert(
            projectId=project_id,
            body=job_data).execute(num_retries=3)

        logging.info(response)

        return
예제 #4
0
import model.book as book_mgt
from lib import httplib2

from lib.googleapiclient.discovery import build

from lib.oauth2client.contrib import appengine

from model.appinfo import AppInfo

http = httplib2.Http(memcache)

decorator = appengine.oauth2decorator_from_clientsecrets(
    'client_secret.json',
    scope='https://www.googleapis.com/auth/books',
    message="MISSING_CLIENT_SECRETS_MESSAGE")
service = build("books", "v1", http=http)


class AddBook(webapp2.RequestHandler):
    @decorator.oauth_required
    def get(self):

        user = users.get_current_user()
        usr_info = usr_mgt.retrieve(user)

        if user and usr_info:

            access_link = users.create_logout_url("/")
            template_values = {
                "info": AppInfo,
                "access_link": access_link,
import logging
from httplib2 import ServerNotFoundError

logger = logging.getLogger("webradio")

from lib.googleapiclient.discovery import build
import pprint
pp = pprint.PrettyPrinter(indent=4)
# Set DEVELOPER_KEY to the API key value from the APIs & auth > Registered apps
# Please ensure that you have enabled the YouTube Data API for your project.
DEVELOPER_KEY = "AIzaSyDs9UiXmNXM_kWtWZWCJTtbYAJ90WQmChE"
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
try:
    youtube = build(YOUTUBE_API_SERVICE_NAME,
                    YOUTUBE_API_VERSION,
                    developerKey=DEVELOPER_KEY)
except Exception, e:
    logger.warning("Could not connect to Youtube: {}".format(e))
    youtube = None


def iso_Date_to_seconds_int(timestring):
    '''
    This function converts an ISO8601 Sting to seconds (in int):
    P is the duration designator (for period) placed at the start of the duration representation.
    Y is the year designator that follows the value for the number of years.
    M is the month designator that follows the value for the number of months.
    W is the week designator that follows the value for the number of weeks.
    D is the day designator that follows the value for the number of days.
    T is the time designator that precedes the time components of the representation.
예제 #6
0
import commands
import logging
from httplib2 import ServerNotFoundError

logger = logging.getLogger("webradio")

from lib.googleapiclient.discovery import build
import pprint
pp = pprint.PrettyPrinter(indent=4)
# Set DEVELOPER_KEY to the API key value from the APIs & auth > Registered apps
# Please ensure that you have enabled the YouTube Data API for your project.
DEVELOPER_KEY = "AIzaSyDs9UiXmNXM_kWtWZWCJTtbYAJ90WQmChE"
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
try:
    youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
                    developerKey=DEVELOPER_KEY)
except ServerNotFoundError:
    logger.warning("Server can not reached, maybe no network is connected?")
    youtube = None

def iso_Date_to_seconds_int(timestring):
    '''
    This function converts an ISO8601 Sting to seconds (in int):
    P is the duration designator (for period) placed at the start of the duration representation.
    Y is the year designator that follows the value for the number of years.
    M is the month designator that follows the value for the number of months.
    W is the week designator that follows the value for the number of weeks.
    D is the day designator that follows the value for the number of days.
    T is the time designator that precedes the time components of the representation.
    H is the hour designator that follows the value for the number of hours.
    M is the minute designator that follows the value for the number of minutes.