Created
September 11, 2017 20:12
-
-
Save jamescoxon/ed5afe1187484ac2435286196c83c1db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import settings | |
| import twitter | |
| import json | |
| import time | |
| import pycurl | |
| from io import BytesIO | |
| import dataset | |
| def wallet_com(data): | |
| buffer = BytesIO() | |
| c = pycurl.Curl() | |
| c.setopt(c.URL, '127.0.0.1') | |
| c.setopt(c.PORT, 7076) | |
| c.setopt(c.POSTFIELDS, json.dumps(data)) | |
| c.setopt(c.WRITEFUNCTION, buffer.write) | |
| output = c.perform() | |
| c.close() | |
| body = buffer.getvalue() | |
| parsed_json = json.loads(body.decode('iso-8859-1')) | |
| return parsed_json | |
| db = dataset.connect('sqlite:///tracking.db') | |
| wallet = settings.wallet | |
| giveaway_address = settings.account | |
| api = twitter.Api(settings.consumer_key, settings.consumer_secret, settings.access_token_key, settings.access_token_secret) | |
| #Add dummy data | |
| #table.insert(dict(name='jaycox', retweets=20, original_id='907318135954591746', retweets_list=None, expiry_time=expiry, per_tweet=2)) | |
| while 1 : | |
| table = db['user'] | |
| for ids in db['user']: | |
| print("\r\n") | |
| print(ids['original_id']) | |
| results = api.GetRetweets(ids['original_id']) | |
| #print(results) | |
| #get retweet details from tracking db | |
| if ids['retweets_list'] is not None: | |
| temp_list = ids['retweets_list'].split(',') | |
| else: | |
| temp_list = [] | |
| num_retweets = int(ids['retweets']) | |
| for replies in results: | |
| print("Replies %s" % replies.user.screen_name) | |
| retweet_description = replies.user.description.split() | |
| for word in retweet_description: | |
| #Check for a xrb address (?64 long and does it start with xrb_) | |
| if (len(word) == 64) and (word[0:4] == 'xrb_'): | |
| #found xrb address | |
| retweet_user = replies.user.screen_name | |
| #print(retweet_user) | |
| retweet_address = word | |
| #print('Current db: %s' % temp_list) | |
| if (retweet_user not in temp_list) and (num_retweets > 0): | |
| print("%s Not in: %s" % (retweet_user, temp_list)) | |
| temp_list.append(retweet_user) | |
| num_retweets = num_retweets - 1 | |
| #Now send mrai | |
| rai_send = float(ids['per_tweet']) * 1000000 #float of total send | |
| raw_send = float(rai_send) * 1000000000000000000000000.0 | |
| print(rai_send) | |
| print(raw_send) | |
| data = {'action' : 'send', 'wallet' : wallet, 'source' : giveaway_address, 'destination' : retweet_address, 'amount' : int(raw_send) } | |
| print(data) | |
| parsed_json = wallet_com(data) | |
| print(parsed_json) | |
| print(ids['per_tweet']) | |
| #Send a DM with result | |
| reply_message = "From @yaprai_wallet retweet system. Here is %sXRB https://raiblockscommunity.net/block/index.php?h=%s" % (ids['per_tweet'], str(parsed_json['block'])) | |
| print(reply_message) | |
| try: | |
| data = api.PostDirectMessage(reply_message, screen_name=retweet_user) | |
| except: | |
| print('Error') | |
| time.sleep(5) | |
| list_for_db = ','.join(temp_list) | |
| print('Final list: %s' % list_for_db) | |
| print('Retweets left: %d' % num_retweets) | |
| table_data = dict(id=ids['id'], retweets=str(num_retweets)) | |
| table.update(table_data, ['id']) | |
| table_data = dict(id=ids['id'], retweets_list=list_for_db) | |
| table.update(table_data, ['id']) | |
| retweets_left = num_retweets | |
| if num_retweets < 1 or (int(time.time()) > int(ids['expiry_time'])): | |
| status = api.PostUpdate('All XRB distributed - thanks for retweeting', in_reply_to_status_id=ids['original_id']) | |
| #Completed the run, now delete the instance | |
| print('Deleting instance') | |
| table.delete(id=ids['id']) | |
| time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment