Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update run.py #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 28 additions & 29 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,26 @@
import json
import time
import tweepy

import requests
ssl._create_default_https_context = ssl._create_unverified_context

# Oauth keys
consumer_key ="XXX"
consumer_secret ="XXX"
access_token ="XXX"
access_token_secret ="XXX"

consumer_key ='ENTER KEY'
consumer_secret = 'ENTER KEY'
access_token = 'ENTER KEY'
access_token_secret = 'ENTER KEY'
# Authentication with Twitter
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
#LunarCRUSH API Key
api_key = "XXX"

api_key = 'ENTER KEY'
# Allows adding as many coins as desired
coin_list = [
"LTC",
"ETH",
"BTC"
]
coins = ','.join(coin_list)

# A list of the fields desired from the API - key is the Lunar Crush key, and the value is the field name outputted to Twitter
# {"LUNAR_CRUSH_KEY": "RENDERED_NAME"}
# For example, to add tweet_replies, you would add:
Expand All @@ -48,7 +44,6 @@
{"news": " News: "},
{"close": " Close: "},
]

def final_render(asset_tweet, value, key, asset):
# As the program becomes more complex, this should be written in a more robust manner
if key == 'symbol':
Expand All @@ -58,26 +53,30 @@ def final_render(asset_tweet, value, key, asset):
else:
asset_tweet += value + str(asset[key])
return asset_tweet


# Iterates over each of the fields from Lunar Crush, gets the value from Lunar Crush and renders it with the field name
def main():

url = "https://api.lunarcrush.com/v2?data=assets&key=" + api_key + "&symbol=" + coins
assets = json.loads(urllib.request.urlopen(url).read())

for asset in assets['data']:
asset_tweet = ""
for field in map:
key = list(field.keys())[0]
value = list(field.values())[0]
asset_tweet = final_render(asset_tweet, value, key, asset)
print(asset_tweet)
print(len(asset_tweet))
# Posts tweets
api.update_status(status=asset_tweet)

# Runs main() every 30 minutes
# url = "https://api.lunarcrush.com/v2?data=assets?&key=" + api_key + "&symbol=" + coins
url = "https://lunarcrush.com/api/v1/assets?symbols=BTC,LTC,ETH&key=" + api_key
print(url)
obj = requests.get(url)
print(obj.text)
try:
assets = json.loads(urllib.request.urlopen(url).read())
print(assets)
for asset in assets['data']:
asset_tweet = ""
for field in map:
key = list(field.keys())[0]
value = list(field.values())[0]
asset_tweet = final_render(asset_tweet, value, key, asset)
print(asset_tweet)
print(len(asset_tweet))
# Posts tweets
api.update_status(status=asset_tweet)
except :
print("Authentication Error")
exit()
# Runs main() every 30 minutes
while True:
main()
time.sleep(1800)