commit 53ad1ade90273ab8b0af6b3c261500fe9ed3dc3f Author: Caleb Fultz Date: Mon Aug 5 09:58:47 2024 -0400 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2413ddb --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +token.secret +image.jpg +image.png +.env \ No newline at end of file diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..f6a49b3 --- /dev/null +++ b/bot.py @@ -0,0 +1,78 @@ +# Import required methods +import random +import os +import sys +from requests import get +from json import loads +from shutil import copyfileobj +from mastodon import Mastodon +from dotenv import load_dotenv + +load_dotenv() + +mastodon = Mastodon( + access_token = os.getenv("token"), + api_base_url = os.getenv("url") +) + +random_number = random.randint(0,160) + +set_code= open('set_codes.txt') +set_total = open('set_total_cards.txt') + +set_code = [line.rstrip('\n') for line in set_code.readlines() if line.strip() != ''] +set_total = [line.rstrip('\n') for line in set_total.readlines() if line.strip() != ''] + +cardid = (set_code[random_number]) +cardtotal = (set_total[random_number]) + +# takes the card set total cards and randomizes the number to pick a card from that set (eg: base1-34) +cardtotal = int(cardtotal) +cardtotal = (random.randint(1,cardtotal)) +cardtotal = str( cardtotal) + +# Load the card data from PokemonTCGAPI + +# This is the actual random card: +card = loads(get(f"https://api.pokemontcg.io/v2/cards/"+cardid+"-"+cardtotal+"").text) + +# Get the image URL +img_url = card['data']['images']['large'] + +# Get card title +poke_title = card['data']['name'] + +# Artist name +poke_artist = card['data']['artist'] + +# Get flavor text +poke_flavor = card['data']['flavorText'] + +# Save the image +with open('image.jpg', 'wb') as out_file: + copyfileobj(get(img_url, stream = True).raw, out_file) + +# Removing weird or unusable characters for hashtags +special_characters=["$","'","`","%","&","(",")",":","?","!","@","*"," "] +for i in special_characters: + hTitle = poke_title.replace(i,"") + hArtist = poke_artist.replace(i,"") + + hArtist = hArtist.replace('.', '') + hArtist = hArtist.replace(',', '') + hArtist = hArtist.replace("'", '') + hTitle = hTitle.replace(',',"") + hTitle = hTitle.replace('.',"") + hTitle = hTitle.replace(':',"") + hTitle = hTitle.replace("'","") + +# Set the Mastodon post information +media = mastodon.media_post("image.jpg", description="Card Name: " + poke_title + "\n" + "Description: " + poke_flavor + "\n" + "Artist: " + poke_artist) + +# Print Text +print (poke_title) +print (img_url) +print (poke_flavor) + +# Post the Toot +print(mastodon.status_post("#pokemon" + " " + "#pokemontcg" + " " + "#" + hTitle + " " + "#" + hArtist,media_ids=media)) \ No newline at end of file diff --git a/set_codes.txt b/set_codes.txt new file mode 100644 index 0000000..c80ffa1 --- /dev/null +++ b/set_codes.txt @@ -0,0 +1,161 @@ +base1 +base2 +basep +base3 +base4 +base5 +gym1 +gym2 +neo1 +neo2 +si1 +neo3 +neo4 +base6 +ecard1 +ecard2 +ecard3 +ex1 +ex2 +ex3 +np +ex4 +ex5 +ex6 +pop1 +ex7 +ex8 +ex9 +ex10 +pop2 +ex11 +ex12 +pop3 +ex13 +ex14 +pop4 +ex15 +pop5 +ex16 +dp1 +dpp +dp2 +pop6 +dp3 +dp4 +pop7 +dp5 +dp6 +pop8 +dp7 +pl1 +pop9 +pl2 +pl3 +pl4 +ru1 +hgss1 +hsp +hgss2 +hgss3 +hgss4 +col1 +bwp +bw1 +mcd11 +bw2 +bw3 +bw4 +bw5 +mcd12 +bw6 +dv1 +bw7 +bw8 +bw9 +bw10 +xyp +bw11 +xy0 +xy1 +xy2 +xy3 +xy4 +xy5 +dc1 +xy6 +xy7 +xy8 +xy9 +g1 +xy10 +xy11 +mcd16 +xy12 +sm1 +smp +sm2 +sm3 +sm35 +sm4 +sm5 +sm6 +sm7 +sm75 +sm8 +sm9 +det1 +sm10 +sm11 +sm115 +sma +mcd19 +sm12 +swshp +swsh1 +swsh2 +swsh3 +swsh35 +swsh4 +swsh45 +swsh45sv +swsh5 +swsh6 +swsh7 +cel25 +cel25c +mcd14 +mcd15 +mcd18 +mcd17 +mcd21 +bp +swsh8 +fut20 +tk1a +tk1b +tk2a +tk2b +swsh9 +swsh9tg +swsh10 +swsh10tg +pgo +swsh11 +swsh11tg +swsh12 +swsh12tg +mcd22 +swsh12pt5 +swsh12pt5gg +sv1 +svp +sv2 +sve +sv3 +sv3pt5 +sv4 +sv4pt5 +sv5 +sv6 +sv6pt5 \ No newline at end of file diff --git a/set_total_cards.txt b/set_total_cards.txt new file mode 100644 index 0000000..1446515 --- /dev/null +++ b/set_total_cards.txt @@ -0,0 +1,161 @@ +102 +64 +53 +62 +130 +83 +132 +132 +111 +75 +18 +66 +113 +110 +165 +182 +182 +109 +100 +100 +40 +97 +102 +116 +17 +111 +108 +107 +145 +17 +114 +93 +17 +111 +100 +17 +101 +17 +108 +130 +56 +124 +17 +132 +106 +17 +100 +146 +17 +106 +133 +17 +120 +153 +111 +16 +124 +25 +96 +91 +103 +106 +101 +115 +12 +98 +102 +103 +111 +12 +128 +21 +153 +138 +122 +105 +216 +140 +39 +146 +110 +114 +124 +164 +34 +112 +100 +165 +126 +117 +129 +116 +12 +113 +173 +250 +180 +177 +81 +126 +178 +150 +187 +80 +240 +198 +18 +234 +260 +69 +94 +12 +272 +304 +216 +209 +201 +80 +203 +73 +122 +183 +233 +237 +25 +25 +12 +12 +12 +12 +25 +9 +284 +5 +10 +10 +12 +12 +186 +30 +216 +30 +88 +217 +30 +215 +30 +15 +160 +70 +258 +129 +279 +8 +230 +207 +266 +245 +218 +226 +99 \ No newline at end of file