def createChain(twitterid): tweet_id = twitterid fct_address = FCT_ADDRESS ec_address = EC_ADDRESS factomd = Factomd(host='http://YourHostAddress:8088', fct_address=fct_address, ec_address=ec_address, username='******', password='******') walletd = FactomWalletd(host='http://YourHostAddress:8089', fct_address=fct_address, ec_address=ec_address, username='******', password='******') resp = walletd.new_chain( factomd, ["TwitterBank Record", str(tweet_id), "frontendrefinement32"], "This is the start of this users TwitterBank Records", ec_address=EC_ADDRESS) chain_ID = resp['chainid'] time.sleep(1) return chain_ID
def getFactomCredentials(EC_ADDRESS, FCT_ADDRESS): fct_address = FCT_ADDRESS ec_address = EC_ADDRESS factomd = Factomd(host='http://18.222.184.135:8088', fct_address=fct_address, ec_address=ec_address, username='******', password='******') walletd = FactomWalletd(host='http://18.222.184.135:8089', fct_address=fct_address, ec_address=ec_address, username='******', password='******') return factomd, walletd
async def process_tweets(twitter_accounts): factomd = Factomd(host=factom_url, ec_address=ec_address, fct_address=fct_address, username='******', password='******') walletd = FactomWalletd(host=wallet_url, ec_address=ec_address, fct_address=fct_address, username='******', password='******') async for twitter_account in twitter_accounts: print('Twitter Account Received!') print(twitter_account) chainid = str(twitter_account.chainid) print('Checking Chain....') chain_id = check_chain(factomd, chainid) print('Chain has arrived at chainhead ' + chain_id) handle = str(twitter_account.handle) tweetid = str(twitter_account.twitterid) print('Gathering Tweets for Factomization for ' + handle) await getAccounts(handle, tweetid, chainid)
currentBin.append(v) else: window = window + windowSize dataBins.append(currentBin[:]) currentBin = [v] dataBins.append(currentBin) # Write to files to store logs locally for data in dataBins: datafile = open('databins/data' + str(i), 'w') json.dump(data, datafile, separators=(',', ':')) chain_id = '35500118f038279a79d7b6a07c7736c6a120332e6866069b558ae71b0617e19e' ec_address = 'EC3gSYeXW1cBbY6u4qDod5Zqrd6u1dDuM5TpMxnkfzbcDQwUKmUV' walletd = FactomWalletd() factomd = Factomd() entryhashes = [] # Write files to blockchain for data in dataBins: content = json.dumps(data, separators=(',', ':')) resp = new_entry(walletd, factomd, chain_id, ['Drone-log', str(random.randint(0, 900000))], content, ec_address=ec_address) entryhashes.append(resp['entryhash']) print(resp['entryhash'])
r_pending_entries = factomd.pending_entries() if any(entry["entryhash"] == entryhash for entry in r_pending_entries): # print('sleeping entryhash: ', entryhash) sleep(1) else: # sleep(1) break # Wallets, remember to import the FCT address and generate the EC address. FCT_ADDR = 'FA2jK2HcLnRdS94dEcU27rF3meoJfpUcZPSinpb7AwQvPRY6RL1Q' EC_ADDR = 'EC1yXtGdZSyYD4yVLhuwSJqfGV4Gph2cSth8QuWCWJ3VQxydYy8c' if __name__ == "__main__": # Default params walletd = FactomWalletd() # You can also specify fct and ec addresses, change host, or specify RPC credentials, for example: factomd = Factomd(host='http://localhost:8088', fct_address=FCT_ADDR, ec_address=EC_ADDR) # ec_address=EC_ADDR, # username='******', # password='******') # Check balance on wallets fct_balance = factomd.factoid_balance(FCT_ADDR) ec_balance = factomd.entry_credit_balance(EC_ADDR) print(f'\n Factoshi (FCT*10^(⁻8)) balance: {fct_balance["balance"]}') print(f'Entry Credit (EC) balance: {ec_balance["balance"]}\n')
def factomizeTweets(tweetid, chainid, factomd, walletd): private_key, public_key = identitykeys.generate_key_pair( ) #generates a public, private key pare private = private_key.to_string() public = public_key.to_string() message = b'TwitterBank Record' signature = private_key.sign(message) sig = signature #base64 encoded pseudo signature fct_address = FCT_ADDRESS ec_address = EC_ADDRESS #initializes factomd --> host will need to be changed to your server address factomd = Factomd(host='http://YourHostAddress:8088', fct_address=fct_address, ec_address=ec_address, username='******', password='******') #initializes walletd --> host will need to be changed to your server address walletd = FactomWalletd(host='http://YourHostAddress:8089', fct_address=fct_address, ec_address=ec_address, username='******', password='******') try: status = api.get_status( int(tweetid )) #uses a tweet id to recreate an entire status/tweet object userid = status.user.id #gets the user or twitterid for the account user_id = str(userid).replace( "'", '"' ) # converts the above string from a single quote string to a double quote string for better JSON representation tweetid = str(status.id) tweet_id = str(tweetid).replace( "'", '"' ) # converts the above string from a single quote string to a double quote string for better JSON representation date = datetime.now() date2 = str(date).replace("'", '"') fct_entry = {"Date_Recorded": date2, "tweet": status._json} print('Sending Tweet to Factom!') tweet = fct_entry["tweet"] try: chain_id = str(chain_id) resp = walletd.new_entry( factomd, chain_id, ["TwitterBank Chain", user_id, tweet_id, public, sig], json.dumps(fct_entry), ec_address=ec_address) # makes entry into the factom testnet entryhash = resp['entryhash'] time.sleep(10) except exceptions.FactomAPIError as e: print(e.data) print('ERROR') return True except tweepy.TweepError: time.sleep(60 * 15) print('this messed up') #continue print('processing next tweet')
while True: r_pending_entries = factomd.pending_entries() if any(entry["entryhash"] == entryhash for entry in r_pending_entries): # print('sleeping entryhash: ', entryhash) sleep(1) else: # sleep(1) break # Wallets, remember to import the FCT address and generate the EC address. FCT_ADDR = 'FA2jK2HcLnRdS94dEcU27rF3meoJfpUcZPSinpb7AwQvPRY6RL1Q' EC_ADDR = 'EC1yXtGdZSyYD4yVLhuwSJqfGV4Gph2cSth8QuWCWJ3VQxydYy8c' if __name__ == "__main__": # Default params walletd = FactomWalletd() # You can also specify fct and ec addresses, change host, or specify RPC credentials, for example: factomd = Factomd(host='http://localhost:8088', fct_address=FCT_ADDR, ec_address=EC_ADDR) # ec_address=EC_ADDR, # username='******', # password='******') # Check balance on wallets fct_balance = factomd.factoid_balance(FCT_ADDR) ec_balance = factomd.entry_credit_balance(EC_ADDR) print(f'\n Factoshi (FCT*10^(⁻8)) balance: {fct_balance["balance"]}') print(f'Entry Credit (EC) balance: {ec_balance["balance"]}\n')
#!/usr/bin/python from factom import Factomd, FactomWalletd import settings factomd = Factomd() walletd = FactomWalletd() walletd.host = settings.WalletdHost factomd.host = settings.FactomdHost print factomd.entry_credit_balance(settings.EntryCredits)
#!/usr/bin/python from factom import Factomd, FactomWalletd import settings, time, re, os factomd = Factomd() walletd = FactomWalletd() walletd.host = settings.WalletdHost factomd.host = settings.FactomdHost Extid1 = 'Test chain entries ' Extid2 = time.strftime("%Y-%m-%d %H:%M") Extid3 = 'Chain creation ' Content = 'Chain entries are dummy values' print factomd.entry_credit_balance(settings.EntryCredits) result = walletd.new_chain(factomd, [Extid1, Extid2, Extid3], Content, settings.EntryCredits) print factomd.entry_credit_balance(settings.EntryCredits) if "chainid" in result: print "CHAIN_ID = " + result["chainid"] else: print "No chain created" print result
def factomizeTweets(tweetid, chain_id): private_key, public_key = identitykeys.generate_key_pair( ) #generates a public, private key pare private = private_key.to_string() public = public_key.to_string() message = b'TwitterBank Record' signature = private_key.sign(message) sig = signature #base64 encoded pseudo signature fct_address = FCT_ADDRESS ec_address = EC_ADDRESS #initializes factomd --> host will need to be changed to your server address factomd = Factomd(host='http://18.222.184.135:8088', fct_address=fct_address, ec_address=ec_address, username='******', password='******') #initializes walletd --> host will need to be changed to your server address walletd = FactomWalletd(host='http://18.222.184.135:8089', fct_address=fct_address, ec_address=ec_address, username='******', password='******') try: status = api.get_status( int(tweetid )) #uses a tweet id to recreate an entire status/tweet object userid = status.user.id #gets the user or twitterid for the account user_id = str(userid).replace( "'", '"' ) # converts the above string from a single quote string to a double quote string for better JSON representation tweetid = str(status.id) tweet_id = str(tweetid).replace( "'", '"' ) # converts the above string from a single quote string to a double quote string for better JSON representation #name = status.user.screen_name #pulls username of tweeter #print('@',name, 'tweeted', status.text) #prints tweet to terminal date = datetime.now() date2 = str(date).replace("'", '"') fct_entry = {"Date_Recorded": date2, "tweet": status._json} print('Sending Tweet to Factom!') tweet = fct_entry["tweet"] try: chain_id = str(chain_id) resp = walletd.new_entry( factomd, chain_id, ['TwitterBank Chain', user_id, tweet_id, public, sig], json.dumps(fct_entry), ec_address=ec_address) # makes entry into the factom testnet #print(' Tweet Successfully Entered Into the Factom Testnet!') print(resp) entryhash = resp['entryhash'] #print(entryhash) #producer.send_messages(str(UserDict[str(userid)]), entryhash.encode('utf-8')) time.sleep(10) #print('Tweet Processed! Waiting For More Tweets to Factomize...') except exceptions.FactomAPIError as e: print(e.data) print('ERROR') return True except tweepy.TweepError: time.sleep(60 * 15) print('this messed up') #continue print('processing next tweet')
#!/usr/bin/python from time import gmtime, strftime from factom import Factomd, FactomWalletd import time, settings factomd = Factomd() walletd = FactomWalletd() walletd.host = settings.WalletdHost factomd.host = settings.FactomdHost timeBetweenEntries = float(settings.TimeInterval) if timeBetweenEntries < 2: timeBetweenEntries = 2 start = 1701 end = 9000 ##################################### ## Open File containing prime numbers ## Store all values in primes array ##################################### f = open("P-1000000.txt", "r") primes = [] for line in f: primes.append(line) ##################################### ## Set entry credit address to spend from ## Set chain ID to add entries to
from utils import filterTweets, getAllTweets, sendTweets, filterTweets, getAllTweets, fromCreator, getKeys, getTwitterCredentials, reconstructTweet private_key, public_key = identitykeys.generate_key_pair() private = private_key.to_string() public = public_key.to_string() message = b'TwitterBank Record' signature = private_key.sign(message) factomd = Factomd(host=factom_url, ec_address=ec_address, fct_address=fct_address, username='******', password='******') walletd = FactomWalletd(host=wallet_url, ec_address=ec_address, fct_address=fct_address, username='******', password='******') #### Consolidates Tweets from an Accounts Timeline into a CSV file that can then be written to Factom async def tweetFetcher(handle, chainid): handle = handle # topic == twitter handle auth = tweepy.OAuthHandler(TWITTER_KEY, TWITTER_SECRET) #Gathers Twitter Keys auth.set_access_token(TWITTER_APP_KEY, TWITTER_APP_SECRET) #Gathers Twitter APP Keys api = tweepy.API(auth) print('Fetching tweets')
def post(self): #Step 1 get the posted data postedData = request.get_json() print(postedData) #Step 2 is to read the data username = users.find_one("Username") # password = postedData["password"] handle = postedData["handle"] twitterid = str(postedData["twitterid"]) # Step3 Generate Chain for Twitter Account factomd = Factomd(host=factom_url, ec_address=ec_address, fct_address=fct_address, username='******', password='******') walletd = FactomWalletd(host=wallet_url, ec_address=ec_address, fct_address=fct_address, username='******', password='******') try: resp = walletd.new_chain( factomd, ['TwitterBank Record', str(twitterid), 'fulltest10'], 'This is the start of this users TwitterBank Records', ec_address=ec_address) chain_ID = resp['chainid'] chainid = chain_ID except FactomAPIError as e: print(e.data) print('ERROR') chainid = str(e.data) # Step 4 Store the Account in the database for a user users.update({ "Username": username, }, { "$set": { "Accounts": [{ "handle": handle, "twitterid": twitterid, "chainid": chainid, "tracking": "yes" }] } }) #Step 5 Send Account to Faust time.sleep(1) account = { "handle": handle, "twitterid": twitterid, "chainid": chainid, } kafka = KafkaClient("kafka:9093") producer = SimpleProducer( kafka, value_serializer=lambda v: json.dumps(v).encode('utf-8')) try: logging.info('sending message %s to kafka', chainid) producer.send_messages('Scribe', json.dumps(account).encode('utf-8')) logging.info('%s sent!', account) except KafkaError as error: logging.warning( 'The message was not sent to the mempool, caused by %s', error) print('Sending Condition to Mempool!') retJSON = { 'handle': handle, 'twitterid': twitterid, 'chainid': str(chainid), } return jsonify(retJSON)