Storylog:
1.Download No more link making using if statements, for now, more on that later. I figured out how to use 'strftime' to format the days and months as always two digits, in a lot less lines.
2.Import 3.Export New path names. Goal: Start whole setup over after mastering virtual environments
5.Archive Daily runtimes are now being calculated using perf_counter and added to a csv file for later performance review.
Here is I my production code for today:
import time
import shutil
import os
from os import rename
import webbrowser
import subprocess
from tkinter import Tk
import csv
# start runtimer
tsubi = time.perf_counter()
#set dates for links and new folder
today = date.today()
tomorrow = today + timedelta(1)
# open links to download and upload images if only I could get out of the way
url1 = f"https://jastic.space/search?after_date={today.strftime("%Y")}-{today.strftime("%m")}-{today.strftime("%d")}T07%3A55%3A00&author=ChartBuddy&before_date={tomorrow.strftime("%Y")}-{tomorrow.strftime("%m")}-{tomorrow.strftime("%d")}T07%3A55%3A00"
url2 = "https://mgur.com/upload"
url3 = "https://www.alkimg.com/"
webbrowser.open(url1)
webbrowser.open(url2)
webbrowser.open(url3)
# 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)
print("Directory '%s' created" %directory)
# learn to scrape 24 images 1 second at a time,
# else manually download each file
# automatically open gimp, then filter to load all images
subprocess.Popen([r'C:/Program Files/GIMP 2/bin/gimp-2.10.exe'])
# export big gif press the any key then enter
print("Is big gif exported?")
input()
print("Movin' on...")
# big gif is moved
src = "C:/PyProjects/tmp/"
dest = "C:/PyProjects/GMIP/2024/2-2024/"
shutil.move("C:/PyProjects/tmp/gif.gif", dest)
rename ("C:/PyProjects/GMIP/2024/2-2024/gif.gif", f"C:/PyProjects/GMIP/2024/2-2024/b{today.month}-{today.day}.gif")
# scale image and export little gif
print("Is little gif exported?")
input()
print("Movin' on...")
# little gif is moved
src = "C:/PyProjects/tmp/"
dest = "C:/PyProjects/GMIP/2024/2-2024/"
shutil.move("C:/PyProjects/tmp/gif.gif", dest)
rename ("C:/PyProjects/GMIP/2024/2-2024/gif.gif", f"C:/PyProjects/GMIP/2024/2-2024/{today.month}-{today.day}.gif")
# ID files
src = "C:/Users/Games/Downloads"
dest = "C:/Users/Games/Downloads/{}".format(directory)
files = os.listdir(src)
os.chdir(src)
# i have a dummy file present so new downloads look like download(*).png
# only move numbered png files
for file in files:
if os.path.isfile(file):
if file.endswith(").png"):
shutil.move(file, dest)
# upload to two sites, gather links to input into console
ibg = input("imgur big gif link here")
imgtalk = input("imgtalk little gif link here")
# add post to clipboard for btctalk
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(f"ChartBuddy's 24 hour Wall Observation recap\n[url={ibg}].{imgtalk}.[/url]\nAll Credit to [url=https://bitcointalk.org/index.php?topic=178336.msg10084622#msg10084622]ChartBuddy[/url]")
r.update()
#this holds the post on the clipboard until posted
print("All done?")
input()
#runtime is calculated
tsubf = time.perf_counter()
runtime = {tsubf - tsubi}
# save to csv file
f = open('C:/PyProjects/runtimes.csv', 'a', newline='')
writer = csv.writer(f)
writer.writerow(runtime)
So what was I talking about earlier? How using strftime uses a lot less lines as stringing the if statements together. But after figuring out how to do runtimes, I figured we could do some science!
So I made 10000 links using following methods. I figured out, finally, how to feed a fake date and run it through using mostly the following
for i in range(0, 10000):
# start runtimer
tsubi = time.perf_counter()
# make fake datetime
fake = Faker()
tod = fake.future_datetime('+50y', None)
tom = tod + timedelta(days = 1)
if statements, with random date: 26.7698 ms per link created
strftime, with imported date: 0.0158472 ms per link created
Wow, total destruction for the if method. Or is it? We might need more data.
Hold on I'm going to go run this code, and then I'll post the runtime.
Sweet the runtime was: crash and burn, okay, okay, but for real this time it was all my fault. See, when you try to test your code you need dummy files to be moved around, and if those dummy files don't get deleted before the next run then python says, "Hey dummy, since your dummy files are there it would be quite rude of me to just copy over them so I'm going to set this bird down as gently as possible." It would have worked, I know this because I did delete the dummy files, change the web addresses to avoid reloading those, re ran the script with the already downloaded files and away we went. Let's see what that unofficial runtime was, well I also forget to click the last enter to stop the timer so it came out to 600.84 s. Seems to be working though. Sweet. Till next time, same python time, same python channel.