One click! One click! One click! No, not 3 clicks, I said One click!, but it's actually, much, much, more! How's that you ask? Well, in one click, sorry, in One click!, i got the post, with proper gif, posted to the WO thread. But for reasons i can't figure out yet, the imgur.com clickable link came out using 2-23 data.
So i needed clicks to fix. Must be something to do with testing, but the code i ran is below. I also successfully failed, sailed, in step 4, when the 'my way' multi step solution to a simple answer, went wrong, yet showed the way. Went wrong in the sense that there are many parts to solving a problem, it's not just the solving part. Effort should be put into identifying the variables, and how the variables affect the outcome. If I had mapped out all the outcomes, I might have seen from step one, just applying my pyautogui commands to the static link i've hard coded, would've been much easier.
1.Download 2.Import 3.Export I need to figure out what to do on days with less than 24 downloads. Also I'm going to work on less file movement, just put it where is going and call it from there when needed. Before that I should understand virtual environments better.
4.Posting I'm looking forward to removing all the pyautogui, and using the command line. But if I'm logged into BCT and imgur, everything should work with one click.
I had a plan and i executed it, but it ain't pretty.
I figured out my way to get the most recent page of the WO Observer thread by looking at the first page source of the thread, which is a static link, to find the link to the last page of the thread at the bottom of the page. I had some fun with that, because of my ignorance of the finer differences between strings, and lists. But with a little help from copilot we powered on. I now see one could also find the link to the most current page number, on the reply page to that thread. ATTN: Code Error produced 1000 not the desired 661080 or i guess it should have been 661060, since this particular post is the first on a new page. OR ya big doofus, that's me, just hit reply on the first page and let the forum code handle on how to post it as the most recent post.
I realized this, when my solution failed and sent me to some other page rather than the last one, but since pyautogui mindlessly went on to hit reply, everything worked out okay, for that part. Phew, at least i was in the proper thread.
5.Archive I just learned that pyautogui can also click and drag, so it should be possible, for fun, to drag all the images from every day this month into GIMP. Maybe set up another race...
It would be good practice for loops and functions maybe. I'm seeing a function that auto double-clicks the first day's folder, at (x, y) then select all, ctrl + a. This way, there is no need to know how many images are in each day to move. Then click and drag into gimp, go back to previous folder and loop around with (x, y + 20) or wherever the next day's folder is. Hmm.
I would need to know how many folders there are, or I could change the name of the folder to include a variable number that goes up by one each time a new day is added, then just cut it out of the directory name to plug into the mouse moving function, at the end of the month.
2-25 run code runtime = 313.0 s
import csv, os, pyautogui, pyperclip, re, requests, shutil, time, urllib.request, webbrowser
from datetime import timedelta, date
from os import rename
startTime = time.perf_counter()
# set dates for links and new folder
today = date.today()
tomorrow = today + timedelta(1)
# get the final 20 gif layers in reverse order, starting with 24
number = 24
url4 = 'https://bitcointalk.org/index.php?action=profile;u=110685;sa=showPosts;start=0'
response = requests.get(url4)
# turn response into textfile of the source code.
source_code = response.text
# read the source code, save it, and turn it into a string.
textfile = open('C:/Users/Games/CBSource.txt', 'a+')
textfile.write(source_code)
textfile.seek(0)
filetext = textfile.read()
textfile.close()
# find matches using regex, and for every match download the image and number it. resorted to asking copilot for help with my regex
matches = re.findall(r'https:\/\/www\.talkimg\.com\/images\/\w{4}/\w{2}\/\w{2}\/\w{5}\.png', filetext)
for link in matches:
print(number, link)
urllib.request.urlretrieve(link, 'download ({}).png'.format(number))
number = number - 1
time.sleep(5)
os.remove('C:/Users/Games/CBSource.txt')
# get the first 4 images in reverse order, i copied my own code and changed the link. Should have made a function and then fed it the links probably.
url5 = 'https://bitcointalk.org/index.php?action=profile;u=110685;sa=showPosts;start=20'
response5 = requests.get(url5)
source_code = response5.text
textfile5 = open('C:/Users/Games/CBSource2.txt', 'a+')
textfile5.write(source_code)
textfile5.seek(0)
filetext = textfile5.read()
textfile5.close()
# find matches using regex, and for first 4 matches download the image and number it
matches = re.findall(r'https:\/\/www\.talkimg\.com\/images\/\w{4}/\w{2}\/\w{2}\/\w{5}\.png', filetext)
for link in matches:
if number >= 1:
urllib.request.urlretrieve(link, 'download ({}).png'.format(number))
print(number, link)
number = number - 1
time.sleep(5)
os.remove('C:/Users/Games/CBSource2.txt')
# move em where they usually go, repurposing code
src = "C:/Users/Games/"
dest = "C:/Users/Games/Downloads/"
files = os.listdir(src)
os.chdir(src)
# only move numbered png files
for file in files:
if os.path.isfile(file): # probably don't need this because of the next if?
if file.endswith(").png"):
shutil.move(file, dest)
# name newfolder with date
directory = f"{today.month}-{today.day}"
parent_dir = "C:/Users/Games/Downloads"
newf = os.path.join(parent_dir, directory)
os.mkdir(newf)
# make sure everything is in the right place, no need to rush. yet :)
# command for show desktop, and clicking an empty region on the proper monitor
time.sleep(5)
pyautogui.hotkey('win', 'd')
time.sleep(5)
pyautogui.click(1, 1)
time.sleep(5)
# hot keys to open gimp and then the plugin that load layers, export, scale, export gifs, quit, agree to not save
pyautogui.hotkey('ctrl', 'alt', 'g')
time.sleep(10)
pyautogui.hotkey('ctrl', 'alt', 'l')
time.sleep(5)
pyautogui.hotkey('tab')
time.sleep(1)
pyautogui.hotkey('tab')
time.sleep(1)
pyautogui.hotkey('tab')
time.sleep(1)
pyautogui.hotkey('enter')
time.sleep(10)
pyautogui.hotkey('ctrl', 'q')
time.sleep(5)
pyautogui.hotkey('shift', 'tab')
time.sleep(1)
pyautogui.hotkey('enter')
time.sleep(5)
# uploading big gif and getting link to use later,
url = "https://api.imgur.com/3/image"
payload = {'name': f'b{today.month}-{today.day}'}
files=[('image',('gif.gif',open('gif.gif','rb'),'image/gif'))]
headers = {'Authorization': 'Bearer f0e27b94e6f8ead1480763e666c8587b73365850'}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
# find imgur url from api response
imgur_return = response.text
linkfile = open('C:/Users/Games/imgurlink.txt', 'a+')
linkfile.write(imgur_return)
linkfile.seek(0)
filetext = linkfile.read()
linkfile.close()
imgurlink = re.findall(r'https:\/\/i\.imgur\.com\/.*\.gif', filetext)
# ibg = imgurlink
# print (ibg)
# if i don't do it this way, the link comes out with ['brackets and quotes']
# that's probably because what i've been 're turned' is a list
# and the following only works because it's the only link in the JSON response
for imgur in imgurlink:
ibg = imgur
os.remove('C:/Users/Games/imgurlink.txt')
# big gif is stored
src = "C:/Users/Games/Postman/files/gif.gif"
dest = f"C:/PyProjects/GMIP/{today.year}/{today.month}-{today.year}/"
shutil.move("C:/Users/Games/Postman/files/gif.gif", dest)
rename (f"C:/PyProjects/GMIP/{today.year}/{today.month}-{today.year}/gif.gif", f"C:/PyProjects/GMIP/{today.year}/{today.month}-{today.year}/b{today.month}-{today.day}.gif")
# open imgtalk to upload gif2
url3 = "https://www.talkimg.com/"
webbrowser.open(url3)
# pyautogui to the rescue
time.sleep(10)
pyautogui.click(953, 590)
time.sleep(5)
pyautogui.click(221, 479)
time.sleep(5)
pyautogui.typewrite("gif2.gif")
time.sleep(5)
pyautogui.hotkey('tab')
time.sleep(1)
pyautogui.hotkey('tab')
time.sleep(10)
pyautogui.hotkey('enter')
time.sleep(5)
pyautogui.click(949, 645)
time.sleep(5)
pyautogui.click(1276, 625)
time.sleep(5)
imgtalklink = pyperclip.paste()
# little gif is stored
src = "C:/Users/Games/Postman/files/"
dest = f"C:/PyProjects/GMIP/{today.year}/{today.month}-{today.year}/"
shutil.move("C:/Users/Games/Postman/files/gif2.gif", dest)
rename (f"C:/PyProjects/GMIP/{today.year}/{today.month}-{today.year}/gif2.gif", f"C:/PyProjects/GMIP/{today.year}/{today.month}-{today.year}/{today.month}-{today.day}.gif")
# make a list of files in downloads folder
src = "C:/Users/Games/Downloads"
dest = "C:/Users/Games/Downloads/{}".format(directory)
files = os.listdir(src)
os.chdir(src)
# only move numbered png files
for file in files:
if os.path.isfile(file):
if file.endswith(").png"):
shutil.move(file, dest)
# add post to clipboard for btctalk
pyperclip.copy(f"ChartBuddy's 24 hour Wall Observation recap\n[url={ibg}].{imgtalklink}.[/url]\nAll Credit to [url=https://bitcointalk.org/index.php?topic=178336.msg10084622#msg10084622]ChartBuddy[/url]")
# what kind of newb posts their own post? ;)
# this is one way to get the most current wall observer page through the page source
url7 = 'https://bitcointalk.org/index.php?topic=178336.0'
response = requests.get(url7)
# turn response into textfile of the source code.
source_code = response.text
# read the source code, save it, and turn it into a string.
textfile = open('C:/Users/Games/CBSource.txt', 'a+')
textfile.write(source_code)
textfile.seek(0)
filetext = textfile.read()
textfile.close()
os.remove('C:/Users/Games/CBSource.txt')
# look for all the links again
matches = re.findall(r'https:\/\/bitcointalk\.org\/index\.php\?topic=178336\.[0-9]+', filetext)
# start an empty list and fill it with all the links and split off the thread numbers
pages = []
for hit in matches:
res = hit.rsplit('.', 1)[-1]
# res2 = res[1:2:1], oh boy, i just found this comment before runtime, but i searched for res2 and this is the only instance so i'm going for it like this
# “The Times 2/26/2024 07:24 utc DK on brink of second crash.” let's do this
pages.append(res)
# i knew link i wanted was 5 from the end, so start at -5 for, until -6 is hit, -1 each time
# what I figured out to do, but it was coming back [['what I want']]
theone = (pages[-5:-6:-1])
# getting tired so didn't even try, copilot said do this
theone = theone[0].strip('[]')
# I'm back!, time for more autopygui
url7 = 'https://bitcointalk.org/index.php?topic=178336.{}'.format(theone)
webbrowser.open(url7)
time.sleep(5)
pyautogui.click(1171, 347)
time.sleep(5)
pyautogui.hotkey('end')
time.sleep(5)
pyautogui.click(1627, 829)
time.sleep(5)
pyautogui.hotkey('tab')
time.sleep(5)
pyautogui.hotkey('tab')
time.sleep(5)
pyautogui.hotkey('ctrl', 'v')
time.sleep(5)
# hit post!
pyautogui.click(914, 1008)
#runtime is calculated
stopTime = time.perf_counter()
runtime = {stopTime - startTime}
# save to csv file
f = open('C:/PyProjects/runtimes.csv', 'a', newline='')
writer = csv.writer(f)
writer.writerow(runtime)
EDIT: added details about 'semicrash' circumstances