示例#1
0
    def __init__(self, project, bucket, creds=None, google_api_lock=None):
        self.project = project
        self.bucket = bucket

        self.google_api_lock = google_api_lock or threading.RLock()
        self.access_token = Token(service_file=creds,
                                  google_api_lock=self.google_api_lock,
                                  scopes=SCOPES)
示例#2
0
    def __init__(self, project, keyring, keyname, creds=None,
                 google_api_lock=None, location=LOCATION):
        # pylint: disable=too-many-arguments
        self.api_root = ('{}/projects/{}/locations/{}/keyRings/{}/'
                         'cryptoKeys/{}'.format(API_ROOT, project, location,
                                                keyring, keyname))

        self.google_api_lock = google_api_lock or threading.RLock()

        self.access_token = Token(creds=creds,
                                  google_api_lock=self.google_api_lock,
                                  scopes=SCOPES)
示例#3
0
    def __init__(self, project, taskqueue, creds=None, google_api_lock=None,
                 location=LOCATION):
        # pylint: disable=too-many-arguments
        self.api_root = '{}/projects/{}/locations/{}/queues/{}'.format(
            API_ROOT, project, location, taskqueue)

        self.google_api_lock = google_api_lock or threading.RLock()

        self.access_token = Token(creds=creds,
                                  google_api_lock=self.google_api_lock,
                                  scopes=SCOPES)

        self.default_header = {
            'Accept': 'application/json',
            'Content-Length': '0',
        }
示例#4
0
    def __init__(self,
                 project=None,          # type: Optional[str]
                 service_file=None,     # type: Optional[str]
                 namespace='',          # type: str
                 session=None,          # type: Optional[requests.Session]
                 token=None,            # type: Optional[Token]
                 google_api_lock=None,  # type: Optional[threading.RLock]
                 ):
        # type: (...) -> None
        self.namespace = namespace
        self.session = session
        self.google_api_lock = google_api_lock or threading.RLock()

        if IS_DEV:
            self._project = os.environ.get('DATASTORE_PROJECT_ID', 'dev')
            # Tokens are not needed when using dev emulator
            self.token = None
        else:
            self._project = project
            self.token = token or Token(service_file=service_file,
                                        session=session, scopes=SCOPES)
from google.cloud import language
from google.cloud.language import enums, types


#Authentication import
from gcloud.aio.auth import IamClient
from gcloud.rest.auth import Token
client = IamClient()
pubkeys = await client.list_public_keys()
token = Token()
print(token.get())
print("-----------------")



def analyze_text_sentiment(text):
    client = language.LanguageServiceClient()
    document = types.Document(
        content=text,
        type=enums.Document.Type.PLAIN_TEXT)

    response = client.analyze_sentiment(document=document)

    sentiment = response.document_sentiment
    results = [
        ('text', text),
        ('score', sentiment.score),
        ('magnitude', sentiment.magnitude),
    ]
    for k, v in results:
        print('{:10}: {}'.format(k, v))