def main(): assert TOKEN != '', 'You need to set TOKEN. To obtain your token visit https://cryptomood.com/business/products/sentiment-analysis-api/.' # Create credentials for use with an secured channel credentials = grpc.ssl_channel_credentials(open(PATH_TO_CERT_FILE, 'rb').read()) call_credentials = grpc.access_token_call_credentials(TOKEN) credentials = grpc.composite_channel_credentials(credentials, call_credentials) channel = grpc.secure_channel(SERVER_ADDRESS, credentials) # create stub stub = types_pb2_grpc.HistoricDataStub(channel) # create timeframe now = time.time() seconds = int(now) to_time = timestamp_pb2.Timestamp(seconds=seconds) from_time = timestamp_pb2.Timestamp(seconds=to_time.seconds - int(86400 / 4)) # last 6 hours # in our case we have to use kwarg because `from` is # is recognized as python keyword so there would syntax be error # if you want get value you have to use getattr() historic_request_kwargs = { 'from': from_time, 'to': to_time, 'filter': types_pb2.AssetsFilter(assets=['BTC', 'ETH'], all_assets=False)} req = types_pb2.HistoricRequest(**historic_request_kwargs) article_stream = stub.HistoricArticles(req) for article in article_stream: print(article.base.id, article.base.title)
def main(): # Create credentials for use with an secured channel creds = grpc.ssl_channel_credentials(open(PATH_TO_CERT_FILE, 'rb').read()) # Initialize GRPC channel channel = grpc.secure_channel(SERVER_ADDRESS, creds) # create stub stub = types_pb2_grpc.HistoricDataStub(channel) # create timeframe now = time.time() seconds = int(now) to_time = timestamp_pb2.Timestamp(seconds=seconds) from_time = timestamp_pb2.Timestamp(seconds=to_time.seconds - int(86400 / 4)) # last 6 hours # in our case we have to use kwarg because `from` is # is recognized as python keyword so there would syntax be error # if you want get value you have to use getattr() historic_request_kwargs = { 'from': from_time, 'to': to_time, 'filter': types_pb2.AssetsFilter(assets=['BTC', 'ETH'], all_assets=False) } req = types_pb2.HistoricRequest(**historic_request_kwargs) article_stream = stub.HistoricArticles(req) for article in article_stream: print(article.base.id, article.base.title)
def main(): # Create credentials for use with an secured channel credentials = grpc.ssl_channel_credentials( open(PATH_TO_CERT_FILE, 'rb').read()) # uncomment commands below if token auth is required # call_credentials = grpc.access_token_call_credentials('YOUR_TOKEN') # credentials = grpc.composite_channel_credentials(credentials, call_credentials) channel = grpc.secure_channel(SERVER_ADDRESS, credentials) # create stub stub = types_pb2_grpc.HistoricDataStub(channel) # create timeframe now = time.time() seconds = int(now) to_time = timestamp_pb2.Timestamp(seconds=seconds) from_time = timestamp_pb2.Timestamp(seconds=to_time.seconds - int(86400 / 4)) # last 6 hours # in our case we have to use kwarg because `from` is # is recognized as python keyword so there would syntax be error # if you want get value you have to use getattr() historic_request_kwargs = { 'from': from_time, 'to': to_time, 'filter': types_pb2.AssetsFilter(assets=['BTC', 'ETH'], all_assets=False) } req = types_pb2.HistoricRequest(**historic_request_kwargs) reddit_stream = stub.HistoricRedditPosts(req) for reddit in reddit_stream: print(reddit.base.id, reddit.base.content)
def main(): # Create credentials for use with an secured channel creds = grpc.ssl_channel_credentials(open(PATH_TO_CERT_FILE, 'rb').read()) # Initialize GRPC channel channel = grpc.secure_channel(SERVER_ADDRESS, creds) # create stub stub = types_pb2_grpc.HistoricDataStub(channel) now = time.time() seconds = int(now) to_time = timestamp_pb2.Timestamp(seconds=seconds) from_time = timestamp_pb2.Timestamp(seconds=to_time.seconds - int(86400 / 4)) # last 6 hours # in our case we have to use kwarg because `from` is # is recognized as python keyword so there would syntax be error # if you want get value you have to use getattr() historic_request_kwargs = {'from': from_time, 'to': to_time} req = types_pb2.HistoricRequest(**historic_request_kwargs) tweet_items = stub.HistoricTweets(req) for tweet in tweet_items.items: print(tweet.base.id, tweet.base.content)
def main(): # Create credentials for use with an secured channel credentials = grpc.ssl_channel_credentials( open(PATH_TO_CERT_FILE, 'rb').read()) # uncomment commands below if token auth is required # call_credentials = grpc.access_token_call_credentials('YOUR_TOKEN') # credentials = grpc.composite_channel_credentials(credentials, call_credentials) channel = grpc.secure_channel(SERVER_ADDRESS, credentials) # create stub stub = types_pb2_grpc.HistoricDataStub(channel) now = time.time() seconds = int(now) to_time = timestamp_pb2.Timestamp(seconds=seconds) from_time = timestamp_pb2.Timestamp(seconds=to_time.seconds - int(86400 / 2)) # last 12 hours # in our case we have to use kwarg because `from` is # is recognized as python keyword so there would syntax be error # if you want get value you have to use getattr() historic_request_kwargs = { 'from': from_time, 'to': to_time, 'filter': { 'all_assets': True } } req = types_pb2.HistoricRequest(**historic_request_kwargs) tweet_stream = stub.HistoricTweets(req) # dataframe inputs inputs = [] for tweet in tweet_stream: # tweet attributes are defined in proto file author_name = tweet.extended_tweet.author_name content = tweet.base.content sentiment = tweet.sentiment.sentiment inputs.append([author_name, content, sentiment]) df = pd.DataFrame(inputs, columns=['User', 'Content', 'Sentiment']) print(df)