class cryptonews(): def __init__(self, key): self.key = key self.api = CryptoControlAPI(key) self.proxyApi = CryptoControlAPI( key, "http://cryptocontrol_proxy/api/v1/public") def enableSentiment(self): self.sentiment = True def top_news(self, lang=None): return self.api.getTopNews(language=lang) def news_by_coin(self, coin, lang=None): return self.api.getTopNewsByCoin(coin=coin, language=lang) def get_top_tweets(self, coin, lang=None): return self.api.getTopTweetsByCoin(coin=coin, language=lang) def get_reddit(self, coin, lang=None): return self.api.getLatestRedditPostsByCoin(coin=coin, language=lang) def get_top_feed(self, coin, lang): return self.api.getTopFeedByCoin(coin=coin, language=lang) def get_latest(self, coin, lang): return self.api.getLatestItemsByCoin(coin=coin, language=lang) def get_coinDetails(self, coin, lang): return self.api.getCoinDetails(coin=coin, language=lang)
# Connect to a self-hosted proxy server (to improve performance) that points to cryptocontrol.io proxyApi = CryptoControlAPI(key2, "http://cryptocontrol_proxy/api/v1/public") # Get top news print(pd.DataFrame(api.getTopNews()))\ # returned dataframe can be viewed fully in the csv file, same for the other dataframes pd.DataFrame(api.getTopNews()).to_csv('section1/task3/topnews.csv', index=False) # get latest russian news print(pd.DataFrame(api.getLatestNews("ru"))) # # get top bitcoin news print(pd.DataFrame(api.getTopNewsByCoin("bitcoin"))) # get top EOS tweets print(pd.DataFrame(api.getTopTweetsByCoin("eos"))) # get top Ripple reddit posts print(pd.DataFrame(api.getLatestRedditPostsByCoin("ripple"))) # get reddit/tweets/articles in a single combined feed for NEO feed = pd.DataFrame(api.getTopFeedByCoin("neo")) print(feed) # get latest reddit/tweets/articles (seperated) for Litecoin print(pd.DataFrame(api.getLatestItemsByCoin("litecoin"))) # get details (subreddits, twitter handles, description, links) for ethereum links = api.getCoinDetails("ethereum")['links'] print(pd.DataFrame(links))
df = pd.DataFrame(bitcoin) df = df.drop([ 'similarArticles', 'coins', 'source', 'description', 'originalImageUrl', 'url', 'thumbnail' ], axis=1) df.to_csv('bitcoin_data.csv', index=False) # get top EOS tweets eos = api.getTopTweetsByCoin("eos") df = pd.DataFrame(eos) df = df.drop(['text', 'url'], axis=1) df.to_csv('eos_data.csv', index=False) # get top Ripple reddit posts ripple = api.getLatestRedditPostsByCoin("ripple") df = pd.DataFrame(ripple) df = df.drop([ 'similarArticles', 'coins', 'source', 'description', 'originalImageUrl', 'url', 'thumbnail' ], axis=1) df.to_csv('ripple_data.csv', index=False) # get reddit/tweets/articles in a single combined feed for NEO neo = api.getTopFeedByCoin("neo") df = pd.DataFrame(neo) df1 = pd.DataFrame(df[df['type'] == 'article'].article.tolist()) df2 = pd.DataFrame(df[df['type'] == 'reddit'].reddit.tolist()) df3 = pd.DataFrame(df[df['type'] == 'tweet'].tweet.tolist()) df1 = df1.drop([
save_csv(tct, 'top_coin_tweets.csv') # get latest tweets by coin latest_coin_tweets = api.getLatestTweetsByCoin('bitcoin') lct = format_df(latest_coin_tweets) save_j(latest_coin_tweets, 'latest_coin_tweets.json') save_csv(lct, 'latest_coin_tweets.csv') # get Get top reddit posts for a particular coin top_coin_reddits = api.getTopRedditPostsByCoin("bitcoin") tcr = format_df(top_coin_reddits) save_j(top_coin_reddits, 'top_coin_reddits.json') save_csv(tcr, 'top_coin_reddits.csv') # get latest Ripple reddit posts latest_coin_posts = api.getLatestRedditPostsByCoin("ripple") lcp = format_df(latest_coin_posts) save_j(latest_coin_posts, 'latest_coin_post.json') save_csv(lcp, 'latest_coin_posts.csv') # get reddit/tweets/articles in a single combined feed for NEO(sorted by time) top_coin_feed = api.getTopFeedByCoin("bitcoin") tcf = format_df(top_coin_feed) save_j(top_coin_feed, 'top_coin_feed.json') save_csv(tcf, 'top_coin_feed.csv') # get a combined feed (reddit/tweets/articles) for a particular coin # (sorted by relevance) latest_coin_feed = api.getLatestFeedByCoin('bitcoin') lcf = format_df(latest_coin_feed) save_j(latest_coin_feed, 'latest_coin_feed.json')