Skip to content

Instantly share code, notes, and snippets.

@Jontes-Tech
Created March 23, 2022 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jontes-Tech/d4c7c89dd2a9840bfcab500845ffc694 to your computer and use it in GitHub Desktop.
Save Jontes-Tech/d4c7c89dd2a9840bfcab500845ffc694 to your computer and use it in GitHub Desktop.
Tweets Primes
import tweepy as tp
import time
import os
# credentials to login to twitter api
consumer_key = 'removed'
consumer_secret = 'removed'
access_token = 'removed'
access_secret = 'removed'
# login to twitter account api
auth = tp.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tp.API(auth)
# checking for prime
def is_prime(n):
if n <= 1:
return False
else:
for i in range(2, n):
# checking for factor
if n % i == 0:
# return False
return False
# returning True
return True
def onsuccess(winner):
file = open("lastprime.txt", "w")
file.write(winner)
file.close
api.update_status("The next prime number is..."+winner+" Come back in hour for the next number!")
file = open("lastprime.txt", "r")
tempstring = file.read()
trynumber = int(tempstring)
file.close
success = False
while success == False:
trynumber += 1
if is_prime(trynumber):
success = True
onsuccess(str(trynumber))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment