Bitcoin Forum
April 30, 2024, 11:16:50 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 3 »  All
  Print  
Author Topic: My journey from user, to cyborg, to maybe coding a bot.  (Read 925 times)
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 05, 2024, 02:24:13 AM
Last edit: February 24, 2024, 08:10:50 AM by DirtyKeyboard
Merited by hugeblack (10), LoyceV (6), cryptoaddictchie (1)
 #1

Backstory:  In the Wall Observation Thread there is a great bot, ChartBuddy, coded by Richy_T that posts the bitcoin bid and ask walls from the bitstamp exchange, on an hourly basis.  A few months ago, a WO regular, OgNasty, asked "Has anybody created some sort of animated gif using the latest chart buddy images? It might be funny to use the last 24 images on a rolling basis to give you a feel for how the last day has gone. Or maybe grab 24 images once a day and then be able to show each day’s movement. Seems like something one of you fellas would enjoy creating."

Having previously made animated GIF files from image layers in GIMP, I knew I was up for at least the second request.
Here are the steps I iterated each day at the beginning.

1. Scroll through the day and download each ChartBuddy post.  
2. Drag each downloaded image into GIMP as a new layer
3. Export full size gif to imgur for the clickable link, and export optimized gif for the in-thread talkimg hosted one
4. Put together the post and post
5. Archive images for later use in a monthly replay

Even though it was only taking about 5-10 minutes, after a few days i desired to automate, or at least streamline, some of those steps.  I've done some 'fake' programming in games like, TIS100, SpaceChem, and Human Resource Machine.  Well I do have some experience with BASIC and LOGO from back in the day, but now I wanted to learn a little Python.  The first process I wanted to automate was the downloading of the previous day's ChartBuddy images.  Off to YouTube to do some research!  It turns out to be one of the last things it seems like i'm going to be able to do.  These dang electric winged minions keep bringing back bowls of soup and I want downloads.  More on that later.

The first streamline I learned rather quickly was that I could drag all 24 images in GIMP at once, and they would stay in order.  That was a nice one to find first.  Also helpful how Windows appends numbers to identically named files as you download them.  Then I figured out that if I have a 'dummy' download.png file present, the downloads would be perfectly numbered from 1 to 24.  Sweet.

I'm posting this to possibly provide a chuckle from my mistakes, and maybe even encourage other people to learn how to code.  I've been having some frustration, but it's been a ton of fun along the way. It has to be fun if they make fun games about it, right?   Full disclosure: I have typed snippets of a lot of other people's code, never copy and pasted other's code, and generally done a bunch of problem solving.  Along the way I've started to learn a little about Python.  The little game I've been playing is I get more points for getting the answer by searching from Brave browser, medium points for going to Google, and then the least points from asking Copilot.  What an amazing resource that Copilot is. Here's my current status mostly chronologically marking my progress. All the while, I keep giving BeautifulSoup another go.  I think the furthest I've gotten on that front is to have it return all the links on a thread page, and I can see ChartBuddy's user id number, but can't figure out how to sift through it with code, yet.  

1.Download  I've discovered Ninjastic Space and how I can get all of ChartBuddy's posts from the last 24 hours on one page, and more easily right click save them.  I made sure it was okay with TryNinja the site operator to do so.  
   Then, knowing that the search parameters were in the ninjastic space website address for the returned results page, i could just make the link myself each day, by editing a few numbers using notepad
Code:
https://ninjastic.space/search?after_date=2024-01-27T07%3A55%3A00&author=ChartBuddy&before_date=2024-01-28T07%3A55%3A00
  See the user, date and time in there?
   My next progress is where I first used python, to make the link for me for that day. An example of a problem that i still need to work on: The ninjastic space website puts zeros in front of single digit days and months in the search result's url which isn't how I'm getting them from datetime in python.  So I've been manually putting the zero in the code when needed.  I know there is a bunch of ways to format the time, but I'm looking to maybe use this problem as an 'if else' learning exercise for now.

5.Archive I learned how to have python make a folder, named after the date, and move all of that days images into it, no more download(25).pngs for me after forgetting to move yesterday's images.  I strung together the link making code and folder making code, and put an input in the middle so it waits for me to make the gifs before archiving the layers.   What a world!

4.Post  Before I knew about ninjastic space, to speed up inputting the actual post, I would go to the first image for that day's gif, in the WO Observation thread, duplicate that tab.  I would use one tab so I could reply to my last gif, delete the quote code, and then just copy in the new urls, after using the other tab to scroll through the day downloading each ChartBuddy post as I went.  I currently use the draft feature to get the post, but now I see how I can have python write the post for me. I wonder if it can put the post directly on the clipboard for me?

At this point, the process takes about 5-10 minutes, but let's keep going

3.Export  This one took awhile, spending a few days on trying to wrap my head around GIMP plugins to save a gif, this one I had to go to Microsoft Copilot and it calmly told me that the plugin text from the GIMP python console was wrong about file_gif_sav2, and it gave me the correct, newer Parameters to use.  Incredible, what a time to be alive!

Next goals:  Auto importing the layers into GIMP, especially for the monthly version, and having python write the post, accepting the links as inputs.  Let me know if you have any questions I might be able to answer.  Smiley

EDIT: added details about search parameters being in the webaddress, grammar, typo, changed a few to 5-10

█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
In order to achieve higher forum ranks, you need both activity points and merit points.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714519010
Hero Member
*
Offline Offline

Posts: 1714519010

View Profile Personal Message (Offline)

Ignore
1714519010
Reply with quote  #2

1714519010
Report to moderator
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 05, 2024, 06:33:02 AM
Last edit: February 05, 2024, 08:06:23 AM by DirtyKeyboard
Merited by hugeblack (4), LoyceV (1)
 #2

Big progress!

Here's the code (being a single digit month, and day) I've sewn together so far.  I read what I thought looked like a great tip.  Write your comments first on what you want that part of the code to do.  And while I could explain pretty well what each section is doing, there is no way just by looking at my comments could I come up with the code off the top of my head, but some of it like setting variables...well that's about the only thing.  Well i can run an if loop if I remember the colon after the if statement.  but it will do no more than print something.

Code:
from datetime import timedelta
import datetime
import shutil
import os
import webbrowser

#set dates for link range and newf
tod = datetime.date.today()
tom = tod + timedelta(days = 1)

#create link
def CBuddy():
    link = f"https://ninjastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-0{tom.day}T07%3A55%3A00"
    return link
print(CBuddy())

#open link
url = CBuddy()
webbrowser.open_new_tab(url)

#name newfolder with date
directory = f"{tod.month}-{tod.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, press the any key then enter
print("Are files downloaded?")
input()
print("Movin' on...")

#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)  

print("Files moved.")

#open gimp, export two gifs
#upload to two sites, gather links
#post to btctalk

Changelog:
1.Download  The ninjastic space link now auto opens

2.Import Saving me just a few seconds, but should be helpful if I fully automate the process, I wrote a GIMP plugin to load the base image, and then to load each layer in order automatically.  So I only have to open GIMP and click this script.  Before I would drag the base layer desktop icon onto the GIMP icon, opening it, and then highlight the day's downloads and drag them in and then run a plug in I found to reverse all the layers   Here's that code that places the next hour after in the gif, or before in the layers by giving the new layer a layer value of -1.
Code:
import sys, os, re, traceback
from collections import namedtuple
from gimpfu import *
from pdb import *

def plugin_loadlay(image, drawable):
    
    image = pdb.gimp_file_load("C:/Users/Games/Downloads/download (0).png", "/download (0).png")
    display = pdb.gimp_display_new(image)

    for items in range(1,25):
        location = r"C:/Users/Games/Downloads/2-3/download ({}).png".format(items)
        layer = pdb.gimp_file_load_layer(image, location)
        pdb.gimp_image_insert_layer(image, layer, None, -1)

register(
        "python-fu-loadlay",
        "blurb: Here is the first text",
        "help: Here is the help text",
        "author: My name",
        "copyright: My company",
        "date: 2020",
        "<Image>/Filters/loadlay",
        "",
        [
        
            
            
            
        ],
        [],
        plugin_loadlay)

I kept using f to modify the image number string like i did with the date, but I have so much more to learn about how to treat strings and variables.  And I think a string is a type of variable along with integers, Booleans, and complex where j is i.  I think I remember reading that.   Well the last time I typed this much while coding I thought i deleted my whole download folder, because it suddenly became inaccessible, but i really only moved it to the root drive which took about 12 hours.  Don't test on your actual data people!  Close one!  Grin

Next steps:  Change my GIMP scripts to run unattended, learning to write a batch command to eventually string all these steps together, Cheers!

EDIT: missing punctuation

█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 06, 2024, 09:06:17 AM
Merited by hugeblack (4), LoyceV (1)
 #3

Big Progress indeed,  Huh things broke yesterday with the GIMP script.  Can you see why?  Here is the current import script
Code:
#!/usr/bin/python

import sys, os, re, traceback
from collections import namedtuple
from gimpfu import *
from pdb import *

def plugin_loadlay(image, drawable):
    
    image = pdb.gimp_file_load("C:/Users/Games/download (0).png", "/download (0).png")
    display = pdb.gimp_display_new(image)

    for items in range(1,25):
        location = r"C:/Users/Games/Downloads/download ({}).png".format(items)
        layer = pdb.gimp_file_load_layer(image, location)
        pdb.gimp_image_insert_layer(image, layer, None, -1)

register(
        "python-fu-loadlay",
        "blurb: Here is the first text",
        "help: Here is the help text",
        "author: My name",
        "copyright: My company",
        "date: 2020",
        "<Image>/Filters/loadlay",
        "",
        [
        
            
            
            
        ],
        [],
        plugin_loadlay)

main()

It seems I keep plugging holes, when I should be fixing the dam so to speak.  For example I have the script to export the gif from gimp in the form of gif.gif
Instead of figuring out how to use datetime to name the gif (i tried) i'm just moving the gif.gif and then renaming it using python, while waiting until I manually scale and export the talkimg sized gif.

Code:
import datetime
from datetime import timedelta
import shutil
import os
from os import rename
import webbrowser

# set dates for link range and newf
tod = datetime.date.today()
tom = tod + timedelta(days = 1)

# create link
def CBuddy():
    link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-0{tom.day}T07%3A55%3A00"
    return link
print(CBuddy())

# open link
url = CBuddy()
webbrowser.open_new_tab(url)

# name newfolder with date
directory = f"{tod.month}-{tod.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, use gimp filter to load all images,
# export big gif press the any key then enter
print("Is big gif exported?")
input()
print("Movin' on...")

#move big gif
src = "C:/Users/Games/tmp/"
dest = "C:/Users/Games/Desktop/GMIP/2024/2-2024/"
shutil.move("C:/Users/Games/tmp/gif.gif", dest)
rename ("C:/Users/Games/Desktop/GMIP/2024/2-2024/gif.gif", f"C:/Users/Games/Desktop/GMIP/2024/2-2024/b{tod.month}-{tod.day}.gif")

#scale image and export little gif
print("Is little gif exported?")
input()
print("Movin' on...")

#move little gif
src = "C:/Users/Games/tmp/"
dest = "C:/Users/Games/Desktop/GMIP/2024/2-2024/"
shutil.move("C:/Users/Games/tmp/gif.gif", dest)
rename ("C:/Users/Games/Desktop/GMIP/2024/2-2024/gif.gif", f"C:/Users/Games/Desktop/GMIP/2024/2-2024/{tod.month}-{tod.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)  

print("Files moved.")

# open gimp, export two gifs
# upload to two sites, gather links
# post to btctalk

Next steps:  Change my GIMP scripts to run unattended, learning to write a batch command to eventually string all these steps together.

Hope!


█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
ImThour
Copper Member
Legendary
*
Offline Offline

Activity: 1400
Merit: 1512


Bitcoin Bottom was at $15.4k


View Profile
February 07, 2024, 11:48:48 AM
Merited by hugeblack (6), LoyceV (4), DirtyKeyboard (1)
 #4

Hi there,

I can see you are really dedicated towards your code and as a Programmer, I would like to contribute something to your code.

1. Start using functions so that you can call it without re-writing the same code again. For example, I made a create_link function.

Code:
def create_link():
    today = datetime.date.today()
    tomorrow = today + timedelta(days=1)
    link = f"https://jastic.space/search?after_date={today.year}-0{today.month}-0{today.day}T07%3A55%3A00&author=ChartBuddy&before_date={today.year}-0{today.month}-0{tomorrow.day}T07%3A55%3A00"
    return link

2. Try to declare constants for PATHs in the start of the code after imports.

Code:
DOWNLOADS_DIR = "C:/Users/Games/Downloads"
TMP_DIR = "C:/Users/Games/tmp"
DESKTOP_DIR = "C:/Users/Games/Desktop/GMIP/2024/2-2024"

I hope this will help you.
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 08, 2024, 07:23:11 AM
Last edit: February 13, 2024, 10:23:50 AM by DirtyKeyboard
Merited by LoyceV (1)
 #5

Hi there,

~snip~

I hope this will help you.

Wow.  Thank you for those kind words and advice.  Your code looks a lot cleaner for sure.  Smiley
I like the idea of setting variables and paths at the top.  I'm looking forward to knowing more about how to write my own code instead of being able to read it enough to fix the bugs that keep popping up, when I try to integrate another web search snippet.  Maybe I'll be able to by the time GIMP 3.0 is out and I have to rework those functions.  
The answer is probably to write another function, but if I use the date in more than one place would the example you provided work?  I should probably try it myself and see.  

Oh, and I said I didn't straight copy paste anything, I did download a blank gimp-fu plugin template as seen above, because I didn't get all the blurbs and such, but I understand more what those do a bit, and have retyped that plugin, with my own blurbs.

Changelog:
3.Export  I mentioned the improvement in exporting, naming, and storing the gifs, last post.  Now GIMP opens without a click.  Goal: after opening, perform the first filter, but I should probably spend efforts trying to learn to make it run unattended.

4.Post  Now instead of digging for the text of the post in drafts, I saved the text of the post and place it on the clipboard, only a ctrl-v away, until the script ends, which is the reason for the final input. It also now opens both image hosting sites. I just figured out how to have 2 popups ask for the gif urls and auto place them in the text of the post, before being placed on clipboard.  Took me a minute to discover a right click in VS terminal is a paste operation Goal: Have it pull the links straight from the clipboard.  

I think this is what you were talking about I'mThour?  Where instead of typing open url 3 times,  I should create a function called open url and feed it the 3 urls?  Well, I'm just so excited it all worked according to plan.  Thanks again!

Code:
import datetime
from datetime import timedelta
import shutil
import os
from os import rename
import webbrowser
import subprocess
from tkinter import Tk

# set dates for link range and newf
tod = datetime.date.today()
tom = tod + timedelta(days = 1)

# create link
def CBuddy():
    link = f"https://ninjastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-0{tom.day}T07%3A55%3A00"
    return link
print(CBuddy())

# open links to download and upload images if only I could get out of the way
url1 = CBuddy()
url2 = "https://imgur.com/upload"
url3 = "https://www.talkimg.com/"
webbrowser.open(url1)
webbrowser.open(url2)
webbrowser.open(url3)

# name newfolder with date
directory = f"{tod.month}-{tod.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...")

# move big gif
src = "C:/Users/Games/tmp/"
dest = "C:/Users/Games/Desktop/GMIP/2024/2-2024/"
shutil.move("C:/Users/Games/tmp/gif.gif", dest)
rename ("C:/Users/Games/Desktop/GMIP/2024/2-2024/gif.gif", f"C:/Users/Games/Desktop/GMIP/2024/2-2024/b{tod.month}-{tod.day}.gif")

# scale image and export little gif
print("Is little gif exported?")
input()
print("Movin' on...")

# move little gif
src = "C:/Users/Games/tmp/"
dest = "C:/Users/Games/Desktop/GMIP/2024/2-2024/"
shutil.move("C:/Users/Games/tmp/gif.gif", dest)
rename ("C:/Users/Games/Desktop/GMIP/2024/2-2024/gif.gif", f"C:/Users/Games/Desktop/GMIP/2024/2-2024/{tod.month}-{tod.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)  

print("Files moved.")

# 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 [url ={ibg}].{imgtalk}.[/url] All Credit to [url=https://bitcointalk.org/index.php?topic=178336.msg10084622#msg10084622]ChartBuddy[/url]")
r.update()

#this holds the post on the clipboard
print("All done?")
input()

Edit: spelling, phrasing

█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 11, 2024, 06:20:12 AM
Last edit: February 13, 2024, 10:01:47 AM by DirtyKeyboard
Merited by hugeblack (4), LoyceV (1)
 #6

Progress update.  Things are really getting streamlined now, and I also had to do some fixing of my link building process.  

Storylog:
1.Download This one was some fun. Attempting to account for sometimes needing a single digit day and sometimes a double digit day to build that day's ninjastic space link seemed simple enough.  Just check if it's a single or double digit day, and then build the right link.  But I remembered what happened last night, when because the link contains a range of consecutive days, sometimes in the same link it needs to be both single and double digit.  Well that only happens on the 9th day of the month, so that shouldn't be too tough.  But now I was puzzled about the last day of the month, and how I would need to know what that date was to make another exception, and then I remembered this video from Tom Scott The Problem with Time & Timezones - Computerphile, and thought maybe 'if else's' wasn't the brightest way to solve this problem.   Grin

I figured out how to deal with the changing months seeing how I could just add a second 'and' to check if today's month is the same as tomorrow's month, and then copied the needed code for when it was going to be a different month tomorrow.  I stuck with it, and hopefully I'm paying myself by the line, because I cluttered my code with 8 ifs, 11 ands, 1 or, and 1 else, I think I'm good with link making until we switch calendars again, only because the link isn't affected by time zones, leap days, or daylight savings, as far as I can tell.  

I better go triple check after a claim like that...I think I've found at least 5 things that would have gone wrong since typing that.  It worked the one time I tested it earlier for today's date.  Let's find out!  It's the first part of my ever bloating code if you wanted to find the 6th thing.   Wink

I'm thinking a more efficient way to investigate might be learning how to use arrays, and functions to call arrays.

2.Import  Changed script so first file loaded is an .xcf file (GIMP's file extension for a work in progress) and not a .png file so the first image in the gif will retain its frame time, which is longer than the rest.  Created keyboard shortcuts for plug-ins used to import and export files.  Thinking about: as the layers or hours are loaded, place some sort of timekeeping method, I'm thinking relative to midnight UTC, on each frame.  Maybe appearing or dissapearing dots

4.Export  Changed script to include line breaks for automatic post formatting.

Code:
import datetime
from datetime import timedelta
import time
import shutil
import os
from os import rename
import webbrowser
import subprocess
from tkinter import Tk

tsubi = time.perf_counter()

# set dates for link range and newf
tod = datetime.date.today()
tom = tod + timedelta(days = 1)

# check dates and create link
if tod.day < 9 and tod.month <= 9 and tod.month == tom.month:
    # create link for days 1-8 and month 1-9
    def CBuddy():
        link = f"https://ninjastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-0{tom.day}T07%3A55%3A00"
        return link

if tod.day < 9 and tod.month >= 10 and tod.month == tom.month:
    # create link for days 1-8 and month 10,11,12
    def CBuddy():
        link = f"https://ninjastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-0{tom.day}T07%3A55%3A00"
        return link

if tod.day == 9 and tod.month <= 9 and tod.month == tom.month:
    # create link for day 9 with tommorow 10 and month 1-9
    def CBuddy():
        link = f"https://ninjastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-{tom.day}T07%3A55%3A00"
        return link

if tod.day == 9 and tod.month >= 10 and tod.month == tom.month:
    # create link for day 9 with tommorow 10 and month 10,11,12
    def CBuddy():
        link = f"https://ninjastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
        return link

if tod.month <= 8 and tod.month != tom.month:
    # create link for last day of months 1-8
    def CBuddy():
        link = f"https://ninjastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
        return link
    
if tod.month == 9 and tod.month != tom.month:
    # create link for last day of month 9
    def CBuddy():
        link = f"https://ninjastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
        return link
    
if (tod.month == 10 or tod.month == 11) and tod.month != tom.month:
    # create link for last day of month 10,11
    def CBuddy():
        link = f"https://ninjastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
        return link
    
if tod.year != tom.year:
    # create link for last day of the year
    def CBuddy():
        link = f"https://ninjastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tom.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
        return link

else:
    #create double digit links
    def CBuddy():
        link = f"https://ninjastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
        return link

# open links to download and upload images if only I could get out of the way
url1 = CBuddy()
url2 = "https://imgur.com/upload"
url3 = "https://www.talkimg.com/"
webbrowser.open(url1)
webbrowser.open(url2)
webbrowser.open(url3)

# name newfolder with date
directory = f"{tod.month}-{tod.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...")

# move big gif
src = "C:/Users/Games/tmp/"
dest = "C:/Users/Games/Desktop/GMIP/2024/2-2024/"
shutil.move("C:/Users/Games/tmp/gif.gif", dest)
rename ("C:/Users/Games/Desktop/GMIP/2024/2-2024/gif.gif", f"C:/Users/Games/Desktop/GMIP/2024/2-2024/b{tod.month}-{tod.day}.gif")

# scale image and export little gif
print("Is little gif exported?")
input()
print("Movin' on...")

# move little gif
src = "C:/Users/Games/tmp/"
dest = "C:/Users/Games/Desktop/GMIP/2024/2-2024/"
shutil.move("C:/Users/Games/tmp/gif.gif", dest)
rename ("C:/Users/Games/Desktop/GMIP/2024/2-2024/gif.gif", f"C:/Users/Games/Desktop/GMIP/2024/2-2024/{tod.month}-{tod.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)  

print("Files moved.")

# 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 and printed
tsubf = time.perf_counter
print(f"This time it took {tsubf - tsubi:0.4f} seconds")

#save this for later to append a file
runtime = tsubf - tsubi

Next steps:

1.Download: Learn to automate downloading certain images from bct
2.Import: Run GIMP and scripts unattended
3.Export: Learn about imgur's API
4.Post: Learn to auto post on bct
5.Archive: combine a months worth of images

I should put in a timer that keeps track of how long each recap takes.   Let's do that five minutes before posting this, nothing like last minute, untested coding to make things work.  Smiley

Pizza time!

Edit: fixed GMIP typo, grammar

█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
ImThour
Copper Member
Legendary
*
Offline Offline

Activity: 1400
Merit: 1512


Bitcoin Bottom was at $15.4k


View Profile
February 11, 2024, 08:00:27 AM
 #7

Great progress OP, I am personally following your coding progress and I am very happy that you are trying to inspire others and meanwhile logging it for yourself on this platform.
One day, you will get back to this post and wonder how great you could have made this same application and spending way less time but it's all great. I am glad I could help you a bit in it.
It already looks much cleaner and better than the original.
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 11, 2024, 08:21:52 AM
Merited by LoyceV (1)
 #8

Brilliant crash and burn on the foolproof forever solved link creation procedure!
And the timer didn't work either.  The pizza was really tasty though. 

I blame stepping away from the project and being unclear on remembering the problem, namely not needing a single digit day, but being able to deal with a single digit return from datetime.  Which is why i thought the one test i did run in the morning was a success.

Here's the locked in, guaranteed code for sure.  I'll leave it to the reader to spot the changes.  I did clean up a bit after realizing it will never be a new month when the day is below 10. Smiley

Relevant codefix below
Code:
# set dates for link range and newf
tod = datetime.date.today()
tom = tod + timedelta(days = 1)

# check dates and create link
if tod.day < 9 and tod.month <= 9:
    # create link for days 1-8 and month 1-9 formatted like this days 01-08 and month 01-09
    def CBuddy():
        link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-0{tom.day}T07%3A55%3A00"
        return link

if tod.day < 9 and tod.month >= 10:
    # create link for days 1-8 and month 10,11,12
    def CBuddy():
        link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-0{tom.day}T07%3A55%3A00"
        return link

if tod.day == 9 and tod.month <= 9:
    # create link for day 9 with tommorow 10 and month 1-9
    def CBuddy():
        link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-{tom.day}T07%3A55%3A00"
        return link

if tod.day == 9 and tod.month >= 10:
    # create link for day 9 with tommorow 10 and month 10,11,12
    def CBuddy():
        link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
        return link
   
if tod.day > 9 and tod.month <= 9 and tod.month == tom.month:
    # create link for days 1-8 and month 1-9
    def CBuddy():
        link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-{tom.day}T07%3A55%3A00"
        return link

if tod.day > 9 and tod.month >= 10 and tod.month == tom.month:
    # create link for days 1-8 and month 10,11,12
    def CBuddy():
        link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
        return link

if tod.month <= 8 and tod.month != tom.month:
    # create link for last day of months 1-8
    def CBuddy():
        link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
        return link
     
if tod.month == 9 and tod.month != tom.month:
    # create link for last day of month 9
    def CBuddy():
        link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
        return link
     
if (tod.month == 10 or tod.month == 11) and tod.month != tom.month:
    # create link for last day of month 10,11
    def CBuddy():
        link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
        return link
     
if tod.year != tom.year:
    # create link for last day of the year
    def CBuddy():
        link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tom.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
        return link

# test on nonexistent site
url1 = CBuddy()

webbrowser.open(url1)

Great progress OP, I am personally following your coding progress and I am very happy that you are trying to inspire others and meanwhile logging it for yourself on this platform.
One day, you will get back to this post and wonder how great you could have made this same application and spending way less time but it's all great. I am glad I could help you a bit in it.
It already looks much cleaner and better than the original.

I have a few questions about your post, but thanks!  I also wonder how long it will take to know enough to code it from memory, or are you talking improving on the runtime efficiency?  I'm really excited to reach that stage.  It's like in the game https://store.steampowered.com/app/375820/Human_Resource_Machine/ you get a different score for how much you can limit the number of different commands you use, and you also get a score for using fewer lines of code for your program to complete the task.

█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 13, 2024, 07:36:11 AM
Merited by LoyceV (1)
 #9

Last night was another crash and burn, but this one was again my fault.  What happened was that I first started learning with Anaconda and Jupyter, and when I started trying Visual Studio I couldn't import 'requests' like I could in Jupyter.  So after more research, I decided to start over with PowerShell 7 and VisualStudio and Python, not from the Microsoft store.  So I created new paths, but then forgot to update the code before runtime.  See, not my fault.  Smiley  All right.  Now we're having fun.  No more untested code, and more testing!

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:
Code:
from datetime import timedelta, date
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
Code:
# start range
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)
I'd love to share the rest if anyone wants them. So now I could get a sampling of dates that are going through various levels of if statements.  So here are the results:

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.


█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
LoyceV
Legendary
*
Offline Offline

Activity: 3290
Merit: 16577


Thick-Skinned Gang Leader and Golden Feather 2021


View Profile WWW
February 13, 2024, 09:22:33 AM
Merited by DirtyKeyboard (1)
 #10

Wouldn't ImageMagick be easier to automate things than The GIMP?

DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 13, 2024, 09:30:16 AM
Last edit: February 25, 2024, 12:15:50 AM by DirtyKeyboard
 #11

Wouldn't ImageMagick be easier to automate things than The GIMP?

Possibly.  For which step in particular?  I do have prior experience with GIMP and am pleased with how my learning Python is tying in with it.  I'll look into it!

Okay.  I'm sure everyone sees the problem and y'all shouldn't have to wait.  We have two many changing variables.  Wink  Let's make the strftime work with random dates as well.

if statements, with random date:  26.7698 ms per link created,
strftime, with random date:          26.9713 ms per link created

Pretty close there, both have nice results within them, but probably too close to tell without more data.  What if we import the date for both?
lookup today ifs:   0.003934090 ms per link created
strftime lookup:    0.015847180 ms per link created

Seems like the ifs are conclusively faster, but today's date leads to less if statements being tested against, if i understand things, than if it was a 'change of month or year date' link being made.  So I ran those as well, these times are in ms to make one link using the date provided.  Goal: fix this once i figure out tables.  i tried

all numbers are how long it took in milliseconds for each link to be created (ms/link)
lookup today ifs      set date ifs        if new month         if new year        if test rand        strftime lookup      strftime rand
0.00393409               0.00279952       0.00279952         0.002679110             26.7699           0.0158472              26.9713
0.00479044               0.00304908        0.00309240         0.00295039               29.5539           0.0154960              28.9656

But it seems, for now, the 'if' submission will lead to a higher score in time completion, while the 'strftime' will lead to a higher score in the line length competition.  Don't let perfect be the enemy of good.  Keep calm and make mistakes.

Here's all the different code
Code:
>>>...>>>...>>>lookup today ifs
import datetime
from datetime import timedelta
from datetime import date
import time
import shutil
import os
from os import rename
import webbrowser
import subprocess
from tkinter import Tk
import csv
from faker import Faker

# start range
for i in range(0, 10000):
  
    # start runtimer
    tsubi = time.perf_counter()

    # set dates for link range and newf
    tod = date.today()
    tom = tod + timedelta(days = 1)

    # check dates and create link
    if tod.day < 9 and tod.month <= 9:
        # create link for days 1-8 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-0{tom.day}T07%3A55%3A00"
            return link

    if tod.day < 9 and tod.month >= 10:
        # create link for days 1-8 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-0{tom.day}T07%3A55%3A00"
            return link

    if tod.day == 9 and tod.month <= 9:
        # create link for day 9 with tommorow 10 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.day == 9 and tod.month >= 10:
        # create link for day 9 with tommorow 10 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
            return link
        
    if tod.day > 9 and tod.month <= 9 and tod.month == tom.month:
        # create link for days 1-8 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.day > 9 and tod.month >= 10 and tod.month == tom.month:
        # create link for days 1-8 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.month <= 8 and tod.month != tom.month:
        # create link for last day of months 1-8
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if tod.month == 9 and tod.month != tom.month:
        # create link for last day of month 9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if (tod.month == 10 or tod.month == 11) and tod.month != tom.month:
        # create link for last day of month 10,11
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if tod.year != tom.year:
        # create link for last day of the year
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tom.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    #runtime is calculated and printed
    tsubf = time.perf_counter()
  
    # calculate and save to csv file
    runtime = {tsubf-tsubi}    
    f = open('C:/PyProjects/tmp/if_test_nonew.csv', 'a', newline='')
    writer = csv.writer(f)
    writer.writerow(runtime)

>>>...>>>...>>>set date ifs
import datetime
from datetime import timedelta
from datetime import date
import time
import shutil
import os
from os import rename
import webbrowser
import subprocess
from tkinter import Tk
import csv
from faker import Faker

# start range
for i in range(0, 10000):
  
    # start runtimer
    tsubi = time.perf_counter()

    # set dates for link range and newf
    tod = datetime.datetime(2024, 1, 29)
    tom = tod + timedelta(days = 1)

    # check dates and create link
    if tod.day < 9 and tod.month <= 9:
        # create link for days 1-8 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-0{tom.day}T07%3A55%3A00"
            return link

    if tod.day < 9 and tod.month >= 10:
        # create link for days 1-8 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-0{tom.day}T07%3A55%3A00"
            return link

    if tod.day == 9 and tod.month <= 9:
        # create link for day 9 with tommorow 10 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.day == 9 and tod.month >= 10:
        # create link for day 9 with tommorow 10 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
            return link
        
    if tod.day > 9 and tod.month <= 9 and tod.month == tom.month:
        # create link for days 1-8 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.day > 9 and tod.month >= 10 and tod.month == tom.month:
        # create link for days 1-8 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.month <= 8 and tod.month != tom.month:
        # create link for last day of months 1-8
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if tod.month == 9 and tod.month != tom.month:
        # create link for last day of month 9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if (tod.month == 10 or tod.month == 11) and tod.month != tom.month:
        # create link for last day of month 10,11
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if tod.year != tom.year:
        # create link for last day of the year
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tom.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    #runtime is calculated and printed
    tsubf = time.perf_counter()
  
    # calculate and save to csv file
    runtime = {tsubf-tsubi}    
    f = open('C:/PyProjects/tmp/if_test_setdate.csv', 'a', newline='')
    writer = csv.writer(f)
    writer.writerow(runtime)

>>>...>>>...>>>if new month
import datetime
from datetime import timedelta
from datetime import date
import time
import shutil
import os
from os import rename
import webbrowser
import subprocess
from tkinter import Tk
import csv
from faker import Faker

# start range
for i in range(0, 10000):
  
    # start runtimer
    tsubi = time.perf_counter()

    # set dates for link range and newf
    tod = datetime.datetime(2024, 2, 29)
    tom = tod + timedelta(days = 1)

    # check dates and create link
    if tod.day < 9 and tod.month <= 9:
        # create link for days 1-8 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-0{tom.day}T07%3A55%3A00"
            return link

    if tod.day < 9 and tod.month >= 10:
        # create link for days 1-8 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-0{tom.day}T07%3A55%3A00"
            return link

    if tod.day == 9 and tod.month <= 9:
        # create link for day 9 with tommorow 10 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.day == 9 and tod.month >= 10:
        # create link for day 9 with tommorow 10 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
            return link
        
    if tod.day > 9 and tod.month <= 9 and tod.month == tom.month:
        # create link for days 1-8 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.day > 9 and tod.month >= 10 and tod.month == tom.month:
        # create link for days 1-8 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.month <= 8 and tod.month != tom.month:
        # create link for last day of months 1-8
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if tod.month == 9 and tod.month != tom.month:
        # create link for last day of month 9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if (tod.month == 10 or tod.month == 11) and tod.month != tom.month:
        # create link for last day of month 10,11
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if tod.year != tom.year:
        # create link for last day of the year
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tom.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    #runtime is calculated and printed
    tsubf = time.perf_counter()
  
    # calculate and save to csv file
    runtime = {tsubf-tsubi}    
    f = open('C:/PyProjects/tmp/if_test_newmonth.csv', 'a', newline='')
    writer = csv.writer(f)
    writer.writerow(runtime)

>>>...>>>...>>>if new year
import datetime
from datetime import timedelta
from datetime import date
import time
import shutil
import os
from os import rename
import webbrowser
import subprocess
from tkinter import Tk
import csv
from faker import Faker

# start range
for i in range(0, 10000):
  
    # start runtimer
    tsubi = time.perf_counter()

    # set dates for link range and newf
    tod = datetime.datetime(2001, 12, 31)
    tom = tod + timedelta(days = 1)

    # check dates and create link
    if tod.day < 9 and tod.month <= 9:
        # create link for days 1-8 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-0{tom.day}T07%3A55%3A00"
            return link

    if tod.day < 9 and tod.month >= 10:
        # create link for days 1-8 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-0{tom.day}T07%3A55%3A00"
            return link

    if tod.day == 9 and tod.month <= 9:
        # create link for day 9 with tommorow 10 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.day == 9 and tod.month >= 10:
        # create link for day 9 with tommorow 10 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
            return link
        
    if tod.day > 9 and tod.month <= 9 and tod.month == tom.month:
        # create link for days 1-8 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.day > 9 and tod.month >= 10 and tod.month == tom.month:
        # create link for days 1-8 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.month <= 8 and tod.month != tom.month:
        # create link for last day of months 1-8
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if tod.month == 9 and tod.month != tom.month:
        # create link for last day of month 9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if (tod.month == 10 or tod.month == 11) and tod.month != tom.month:
        # create link for last day of month 10,11
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if tod.year != tom.year:
        # create link for last day of the year
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tom.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    #runtime is calculated and printed
    tsubf = time.perf_counter()
  
    # calculate and save to csv file
    runtime = {tsubf-tsubi}    
    f = open('C:/PyProjects/tmp/if_test_newyear.csv', 'a', newline='')
    writer = csv.writer(f)
    writer.writerow(runtime)


>>>...>>>...>>>if test rand
import datetime
from datetime import timedelta
from datetime import date
import time
import shutil
import os
from os import rename
import webbrowser
import subprocess
from tkinter import Tk
import csv
from faker import Faker

# start range
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)

    # check dates and create link
    if tod.day < 9 and tod.month <= 9:
        # create link for days 1-8 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-0{tom.day}T07%3A55%3A00"
            return link

    if tod.day < 9 and tod.month >= 10:
        # create link for days 1-8 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-0{tom.day}T07%3A55%3A00"
            return link

    if tod.day == 9 and tod.month <= 9:
        # create link for day 9 with tommorow 10 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.day == 9 and tod.month >= 10:
        # create link for day 9 with tommorow 10 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-0{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
            return link
        
    if tod.day > 9 and tod.month <= 9 and tod.month == tom.month:
        # create link for days 1-8 and month 1-9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.day > 9 and tod.month >= 10 and tod.month == tom.month:
        # create link for days 1-8 and month 10,11,12
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tod.month}-{tom.day}T07%3A55%3A00"
            return link

    if tod.month <= 8 and tod.month != tom.month:
        # create link for last day of months 1-8
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if tod.month == 9 and tod.month != tom.month:
        # create link for last day of month 9
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-0{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if (tod.month == 10 or tod.month == 11) and tod.month != tom.month:
        # create link for last day of month 10,11
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tod.year}-{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    if tod.year != tom.year:
        # create link for last day of the year
        def CBuddy():
            link = f"https://jastic.space/search?after_date={tod.year}-{tod.month}-{tod.day}T07%3A55%3A00&author=ChartBuddy&before_date={tom.year}-0{tom.month}-0{tom.day}T07%3A55%3A00"
            return link
        
    #runtime is calculated and printed
    tsubf = time.perf_counter()
  
    # calculate and save to csv file
    runtime = {tsubf-tsubi}    
    f = open('C:/PyProjects/tmp/if_test_random.csv', 'a', newline='')
    writer = csv.writer(f)
    writer.writerow(runtime)

>>>...>>>...>>>strftime lookup
import datetime
from datetime import timedelta
from datetime import date
import time
import shutil
import os
from os import rename
import webbrowser
import subprocess
from tkinter import Tk
import csv
from faker import Faker

# start range
for i in range(0, 10000):

    # 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"

    tsubf = time.perf_counter()
  
    # calculate and save to csv file
    runtime = {tsubf-tsubi}    
    f = open('C:/PyProjects/tmp/strftime_test.csv', 'a', newline='')
    writer = csv.writer(f)
    writer.writerow(runtime)

>>>...>>>...>>>strftime rand
import datetime
from datetime import timedelta
from datetime import date
import time
import shutil
import os
from os import rename
import webbrowser
import subprocess
from tkinter import Tk
import csv
from faker import Faker

# start range
for i in range(0, 10000):

    # start runtimer
    tsubi = time.perf_counter()

    # make fake datetime
    fake = Faker()
    today = fake.future_datetime('+50y', None)
    tomorrow = today + timedelta(days = 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"

    tsubf = time.perf_counter()
  
    # calculate and save to csv file
    runtime = {tsubf-tsubi}    
    f = open('C:/PyProjects/tmp/strftime_withR_test.csv', 'a', newline='')
    writer = csv.writer(f)
    writer.writerow(runtime)

Edit: fixed incorrect savefile in set date ifs, response, added another run of data, I must have messed something up with the first run, getting the identical results?  Still pretty close, though, the second run. I put everything into one code box.  I would like to check the code and rerun the tests, and try tables again.


█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 14, 2024, 07:48:40 AM
Last edit: February 15, 2024, 08:19:31 AM by DirtyKeyboard
 #12

Oh wow.  It worked!  Cool  I stopped midway to reread the script and make sure I knew where the first gif was going.  Didn't want a file to already be there.
Plus I always watch the gifs before posting to make sure everything is in order, but that is just a minute or so.   These are definitely rookie numbers: 369.8 seconds

I think with this code, trusting it, getting better at the keyboard shortcuts, and having the right folder open to drag images to the image hosting sites we could get that down to under 60 seconds.  But I know we can automate more, mainly on the downloading the images, and the GIMP processing going unattended.  Heh, I should code a bot to post the nightly runtimes...actually, I won't spam the place up, but that might be good practice, but first things first.

EDIT:
No hiccups 2 days in a row.  Grin  Runtime was 251.3 seconds.  Wasn't in any particular rush, enjoying all the pictures.   Smiley

Next steps:  learn to link gimp plug-ins using scripts running unattended, keep messing around with web scraping, streamline the current script, and I better start working on the script to make the monthly gif.  I should be able to modify the current gimp plugin that loads each day's 24 images, to be a loop inside of a loop.  We'll see. 

█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 16, 2024, 08:20:46 AM
 #13

I messed up again, but it was my fault.  Exploring imgur's api i got logged out, so when I was dragging the gif into imgur i kept getting an error.  I incorrectly attributed this error to imgur being too busy at the moment, which was a message i frequently received when trying to set up postman, but it turns out i wasn't logged in to imgur.  After logging in everything else went according to plan.  Runtime = 335.2 seconds.

Wouldn't ImageMagick be easier to automate things than The GIMP?

Wow, that seems like quite the tool!  I'm not sure I need all the power it provides, so I'm going to stick to GIMP for now.  Thank you though!

Changelog:
GIMP script now autoresizes the big gif into the imgtalk size gif, after exporting.  So I just have to hit Ctrl-Alt-S, click enter in VS, Ctrl-Alt-S again, click enter in VS and feed in the links

█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
LoyceV
Legendary
*
Offline Offline

Activity: 3290
Merit: 16577


Thick-Skinned Gang Leader and Golden Feather 2021


View Profile WWW
February 16, 2024, 08:29:47 AM
Merited by DirtyKeyboard (1)
 #14

Wouldn't ImageMagick be easier to automate things than The GIMP?
Possibly.  For which step in particular?
I can't tell, I've never used The GIMP for automating anything, but I use ImageMagick a lot. I mentioned it because it may be worth looking into.

Wow, that seems like quite the tool!  I'm not sure I need all the power it provides, so I'm going to stick to GIMP for now.  Thank you though!
You're welcome Smiley Having more options is always good Smiley

DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 17, 2024, 10:25:23 AM
 #15

I'm so excited, I figured out how to code a progress bar in GIMP!

I tied the length of the rectangle I was selecting to be paint bucketed, to the frame layer of the gif.

Keep this under your hat, I'm gonna cosplay as a graphic designer tomorrow and see what i can do with this.  My goal is to show when UTC 0:00 is relative to the progress bar.
Code:
https://imgur.com/a/ZC95ndv

https://imgur.com/a/ZC95ndv

Code:
import sys, os, re, traceback
from collections import namedtuple
from gimpfu import *

def plugin_textlay(image, drawable):
   
#load base layer with custom frametime
    image = pdb.gimp_file_load("C:/Users/Games/Downloads/download (0).xcf", "/download (0).xcf")
    display = pdb.gimp_display_new(image)

#load additional layers growing the status bar
    for items in range(1,25):
        xlength = items * 15
        location = r"C:/Users/Games/Downloads/download ({}).png".format(items)
        layer = pdb.gimp_file_load_layer(image, location)
        pdb.gimp_image_insert_layer(image, layer, None, -1)
        pdb.gimp_image_select_rectangle(image, 2, 220, 25, xlength, 30)
        pdb.gimp_drawable_edit_bucket_fill(layer, 0, 340, 10)
       
register(
        "python-fu-textlay",
        "This loads layers and bar",
        "Very specific use case",
        "author: DK",
        "copyright: probably not",
        "date: 2024",
        "<Image>/Filters/textlay",
        "",
        [
           

        ],
        [],
        plugin_textlay)

main()

I'm sure it's the same, but different with how other code works, but I enjoy using Python and being able to define a variable, and then being able to just plug it in here and there.

Latest runtime: 270.9 seconds


█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 18, 2024, 07:19:39 AM
Last edit: February 18, 2024, 10:57:44 AM by DirtyKeyboard
Merited by LoyceV (4)
 #16

I've decided that unless the man himself, Richy_T, says so, I'm not going to alter the images posted.  Back to more faux-ding I guess.  Grin

But I did come up with some prototypes for our perusal. I'd love to post the recap at midnight UTC, but for that we would need full bot mode, I presume.

First up is what I call barlay, for the progress bar and importing the layers together.
Code:
https://imgur.com/a/r1LloJI
https://imgur.com/a/r1LloJI

Next is barlaytouch, which was an accident, but I thought it looked cool.
Code:
https://imgur.com/a/J8b9mQM
https://imgur.com/a/J8b9mQM

Datelay is a prototype only, getting the spacing right on different days would be a lot of ifs to deal with variable kerning. Smiley
Code:
https://imgur.com/a/MwSiujF
https://imgur.com/a/MwSiujF

Then we have the fun ccbarlay, for color changing.  Took me awhile to figure out the the RGB values switched on me from 0-255 to 0-1.0  
Code:
https://imgur.com/a/9Ijom6U
https://imgur.com/a/9Ijom6U

Code:
import sys, os, re, traceback
from collections import namedtuple
from gimpfu import *
import gimpcolor
# personal use of font thanks to https://chequered.ink/font-license/

def plugin_ccbarlay(image, drawable):
    
    image = pdb.gimp_file_load("C:/Users/Games/Downloads/download (0).xcf", "/download (0).xcf")
    display = pdb.gimp_display_new(image)
    colr = 0.0
    colg = 0.75

    

    for items in range(1,25):
        xlength = items * 15
        pdb.gimp_context_set_foreground(gimpcolor.RGB(colr, colg, 0))
        location = r"C:/Users/Games/Downloads/download ({}).png".format(items)
        layer = pdb.gimp_file_load_layer(image, location)
        pdb.gimp_image_insert_layer(image, layer, None, -1)
        pdb.gimp_image_select_rectangle(image, 2, 220, 25, xlength, 20)
        pdb.gimp_drawable_edit_bucket_fill(layer, 0, 340, 10)
        layer = pdb.gimp_text_fontname (image, None, 315, 40, "0:00 UTC ^", 0, True, 30, PIXELS, "Withheld Data")
        pdb.gimp_image_merge_down(image, layer, 1)
        colr = colr + 0.03
        colg = colg - 0.03
        
register(
        "python-fu-ccbarlay",
        "This loads layers with a progress bar",
        "Very specific use case",
        "author: DK",
        "copyright: probably not",
        "date: 2024",
        "<Image>/Filters/ccbarlay",
        "",
        [
            

        ],
        [],
        plugin_ccbarlay)

main()

And saving the best for last, imo, what I call daylay.  This one has the full dark earth at midnight utc.  It was a fun challenge figuring out how to cycle through the 'letters'.
Code:
https://imgur.com/a/XY5vjts
https://imgur.com/a/XY5vjts

Code:
from gimpfu import *
import gimpcolor
# personal use of font called moon_phases.ttf thanks to Curtis Clark

def plugin_daylay(image, drawable):
    
    image = pdb.gimp_file_load("C:/Users/Games/Downloads/download (0).xcf", "/download (0).xcf")
    display = pdb.gimp_display_new(image)
    pdb.gimp_context_set_foreground(gimpcolor.RGB(58, 118, 222))
  
    # loads layers and prints moondings u - t skipping z and a, so that the m full moonding happens at 0:00 utc
    for items in range(1,25):
        location = r"C:/Users/Games/Downloads/download ({}).png".format(items)
        layer = pdb.gimp_file_load_layer(image, location)
        pdb.gimp_image_insert_layer(image, layer, None, -1)
        
        #these ifs use the proper fudge factor for the layer number conversion to ascii number
        if items <= 5:
            i = items + 116
            alpha = chr(i)
            layer = pdb.gimp_text_fontname (image, None, 365, 0, alpha, 0, True, 80, PIXELS, "day Phases")
            pdb.gimp_image_merge_down(image, layer, 1)
        
        if items >= 6:
            i = items + 92
            alpha = chr(i)
            layer = pdb.gimp_text_fontname (image, None, 365, 0, alpha, 0, True, 80, PIXELS, "day Phases")
            pdb.gimp_image_merge_down(image, layer, 1)
      

register(
        "python-fu-daylay",
        "This loads layers with a progress bar",
        "Very specific use case",
        "author: DK",
        "copyright: probably not",
        "date: 2024",
        "<Image>/Filters/daylay",
        "",
        [
            

        ],
        [],
        plugin_daylay)

main()

So while I had a lot of fun today, and know more about GIMP now, I think the biggest thing I realized is it looks like it's time to learn more about ImageMagick. Smiley
But I have the scripts if anyone has a cool font or color you think I might like.  

Latest runtime: 279.1 seconds, and I had to put back the plug in I really wanted, and restart GIMP so that's around 15 seconds...Edit: spelling

█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 21, 2024, 08:31:19 AM
Last edit: February 21, 2024, 09:11:32 AM by DirtyKeyboard
Merited by LoyceV (4), hugeblack (4)
 #17

It was the best of times, it was the worst of times.
Three days with no runtimes.  The first two were because I knew the code would fail.  I have no error handling for what happens if ChartBuddy decides to take an hour off, to maybe go out for a pizza.  So I didn't even try.  

But now!  Such progress!  I found the pages on bitcointalk.org that have ChartBuddy's last 20 posts , and I have the auto download code, and it worked!  It's not the best way or the fastest way probably, and i needed copilot's help, but it is definitely my way. Smiley Because it then crashed.  Huh  But, here is the relevant new code, and with no BeautifulSoup, i only needed the page source to grab the links.  I knew the links would be in the form of https://www.talkimg.com/images/(4 digit year)/(2 digit month)/(2 digit date)/*****.png, where only the last 5 bits of the file would be different.  I tried and tried, but had to resort to copilot to get my regex correct.
Code:
# get the last 20 images in reverse order, starting with 24, ChartBuddy is user 110685
url = 'https://bitcointalk.org/index.php?action=profile;u=110685;sa=showPosts;start=0'

# send a get request and get the response object
response = requests.get(url)

# turn response into textfile of the source code, not sure if needed, what else did I request?
source_code = response.text

# read the source code, save it, and turn it into a string.  Why am i saving it if I'm going to delete it, can probably skip this instruction, but it might help with error handling?  
textfile = open('C:/Users/Games/CBSource.txt', 'a+')
textfile.write(source_code)
textfile.seek(0)
filetext = textfile.read()
textfile.close()

number = 24

# find matches using regex, and for every match download the image, and number it.  i 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(link)
    urllib.request.urlretrieve(link, 'download({}).png'.format(number))
    number = number - 1
    time.sleep(5)

#delete the source code
os.remove('C:/Users/Games/CBSource.txt')

One thing i'm still ignorant of, which is okay, is why i can sometimes pass variables directly, sometime one has to use curly brackets, and other times empty curly brackets with defining at the end, but learning is living.

Here is the full script i ran today, which I know is going to work tomorrow, after making a tiny change.  Or maybe it won't. Cheesy  If it does I am going to try and work on error handling. .  
If you can see why this script crashed you are an awesome debugger!  (hint: it happens early  Grin)
Code:
from datetime import timedelta, date
import time
import shutil
import os
from os import rename
import webbrowser
import subprocess
from tkinter import Tk
import csv
import re
import urllib.request
import requests

# start runtimer
startTime = 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://injastic.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://imgur.com/upload"
url3 = "https://www.talkimg.com/"
webbrowser.open(url1)
webbrowser.open(url2)
webbrowser.open(url3)

# holy cow is this going to work all together on the first try
# get the last 20 images in reverse order, starting with 24
# set the file numbering start
number = 24

# get the last 20 images in reverse order, starting with 24
url = 'https://bitcointalk.org/index.php?action=profile;u=110685;sa=showPosts;start=0'

# Send a get request and get the response object
response = requests.get(url)

# turn response into textfile of the source code, not sure if needed, what else did I request?
source_code = response.text

# read the source code, save it, and turn it into a string.  Why am i saving it if I'm going to delete it?  
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(link)
    urllib.request.urlretrieve(link, 'download({}).png'.format(number))
    number = number - 1
    time.sleep(5)

#delete the source code
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.
# i renamed everything here with 2, i'm not sure i needed to, but I think I did it correctly
url2 = 'https://bitcointalk.org/index.php?action=profile;u=110685;sa=showPosts;start=20'

# Send a GET request and get the response object
response2 = requests.get(url2)

# turn response into textfile of source
source_code = response2.text

# read the source code and turn it into a string
textfile2 = open('C:/Users/Games/CBSource2.txt', 'a+')
textfile2.write(source_code)
textfile2.seek(0)
filetext = textfile2.read()
textfile2.close()

# find matches using regex, and for first 4 matches download the image and number it
# tried using finditer i think it was to set a limit for the first four results, but i was getting another string, so this seemed like a workaround
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))
        number = number - 1
        time.sleep(5)
        print(link)
    
# delete the soure code
os.remove('C:/Users/Games/CBSource2.txt')

# move em where they usually repurposing code
# ID files
src = "C:/Users/Games/"
dest = "C:/Users/Games/Downloads/"
files = os.listdir(src)
os.chdir(src)

# i have named the new downloads to look like the old manual downloads
# 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)  

#back to the old code
# 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
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 regex, added a line of code defining number to first snippet, changelog soon Smiley  

█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 22, 2024, 08:53:11 AM
 #18

It worked, it worked, we worked! Man and machine in harmony, like the ending of...well I don't want to spoil that one.   Wink The runtime was a surprisingly high at 288.3 s, which I guess I have no reason to doubt, but I should manually test the accuracy of my method.  I did set a delay of 5 seconds between downloads, when manually it was probably in the 2-3 second range between downloads.   But the real savings is in key strokes.  Let's see...graciously estimating
1. Scroll through the day and download each ChartBuddy post.  Scrolling through usually around 4 pages to, right click, left click, enter 24 times, which would be (3*24)+3
2. Drag each downloaded image into GIMP as a new layer Click and drag 24 images, i hope i only did that a few times , 2*24 more actions
3. Export full size gif to imgur for the clickable link, and export optimized gif for the in-thread talkimg hosted one Oh boy, lets remember, export as, 2 clicks, type the name.gif, 5, timing the frames, 4 actions, click scale and choose size, 5 actions, export again, (2+5+4+5)*2
4. Put together the post and post  Let's not count the typing, clicking on 2 bookmarks, 2 click and drags, 6
5. Archive images for later use in a monthly replay  creating a new folder and naming it by date, 7 clicks and keystrokes and a click and drag, 9 = 168 total
168 actions.

And this time it was.  
1.Download: Click run, sit back and relax, 1
2.Import: loading, ctrl-alt-l, 3 tabs, enter, 7
3.Export: ctrl-alt-b, 2 tabs, enter, ctrl-alt-s, 2 tabs, enter, enter to script, 13
4.Post: same, 6
5.Archive: 0
27 actions, most of them mindless clicking through GIMP which I believe can do everything I need it to, all from the command line.  Exciting stuff!

Changelog:
1.Download Wow.  I am now auto downloading the images from BCT, and naming them in the process.

3.Export  I changed the GIMP gif saving plugin, by adding the resize of the gif in the same plugin.  So instead of save, resize, save (which all have keyboard shortcuts), it's now just save, save2.  I've duplicated the GIMP gif saving plugin so I don't have to wait to move the big gif, called, gif.gif before the small gif is exported, which was also called gif.gif.  The small gif is now gif2.gif. Which also means I get to get rid of 2 user inputs, which were only there to stop the code, waiting for me to tell it to proceed. Well, it still has to wait once I guess, but it will be so much faster, one less keystroke for sure. Smiley  

Working on.
2.Import Work in Progress:  I've got a code example of using the command line to start a Python script, that calls GIMP plug ins.  I'm trying to modify it for this purpose.
4.Post I guess I should have been working on that runtime posting bot after all.  Smiley
5.Archive  Blessed with an extra day this month to figure the code for the monthly recap.  

Current Code:
Code:
from datetime import timedelta, date
import time
import shutil
import os
from os import rename
import webbrowser
import subprocess
from tkinter import Tk
import csv
import re
import urllib.request
import requests

# start runtimer
startTime = time.perf_counter()

# set dates for links and new folder
today = date.today()
tomorrow = today + timedelta(1)
      
# open websites to upload gifs
url2 = "https://imgur.com/upload"
url3 = "https://www.talkimg.com/"
webbrowser.open(url2)
webbrowser.open(url3)

# 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(link)
    urllib.request.urlretrieve(link, 'download ({}).png'.format(number))
    number = number - 1
    time.sleep(5)

#delete the source code
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))
        number = number - 1
        time.sleep(5)
        print(link)
    
# delete the soure code
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)
print("Directory '%s' created" %directory)

# learn to scrape 24 images 1 second at a time, yatta!
# 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 gifs press the any key then enter
print("Are the gifs 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")

# little gif is moved
src = "C:/PyProjects/tmp/"
dest = "C:/PyProjects/GMIP/2024/2-2024/"
shutil.move("C:/PyProjects/tmp/gif2.gif", dest)
rename ("C:/PyProjects/GMIP/2024/2-2024/gif2.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)

# 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
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)

█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 25, 2024, 08:51:23 AM
Last edit: February 26, 2024, 08:51:33 AM by DirtyKeyboard
 #19

It didn't work, it didn't work, we. didn't. work.  Big crash, BUT,  huge breakthrough, although I need more testing to make sure this even worked...but.  Huge crashing progress!  With enough pyautoguis we could take over the world!  Firstly, the 2_22 build has worked great the last 2 days with runtimes of 239.2 s, and 252.5 s.  But we need less keystrokes.   Grin

Storylog:
1.Download
Works with a click Smiley

2.Import
Son of a batch.  Gonna take the L on this one for now.  Even copilot said it should be working.  Examples follow
Code:
PATH=%PATH%;"C:\Program Files\GIMP 2\bin"
gimp-2.10 --batch-interpreter python-fu-eval --pdb-compat-mode="on" -b "pdb.python_fu_loadlay" -b pdb.file_gif_save2 (image, drawable, "C:/PyProjects/tmp/gif.gif", "C:/PyProjects/tmp/gif.gif", 0, 1, 1000, 0, 0, 0, 0)

OR

PATH=%PATH%;"C:\Program Files\GIMP 2\bin"
gimp-2.10 --batch-interpreter python-fu-eval -b "pdb.python_fu_loadlay" -b "pdb.file_gif_save2" (image, drawable, "C:/PyProjects/tmp/gif.gif", "gif.gif", 0, 1, 1000, 0, 0, 0, 0)

OR

"C:\Program Files\GIMP 2\bin\gimp-console-2.10.exe" -i --batch-interpreter python-fu-eval -b "pdb.python_fu_loadlay" -b "(gimp-quit 1)"

But with pyautogui, I could just program in the mindless tabs and clicks.  Amazing!  So that I did.
 
3.Export
See above re: pyautogui's cool factor

4.Posting  
Figured out some of imgur's API, and how to crudely hack the link out of the imgur json response, i think, to get the link after uploading.  Full disclosure, i gave up and asked copilot, and then figured out how to make 'my' way work.  Then, there is, my attempt to use pyautogui, to upload a talkimg image and collect the link with no api.  I believe it would have worked, I think,  if I had put the script to sleep for longer, before moving the created gifs.  We'll see tomorrow...
Edge's copilot way
Code:
# Assuming 'api' contains the response object
response_data = json.loads(api.text)
image_link = response_data.get('data', {}).get('link')
ibg = image_link

5.Archive
tick tock

Code with two fails follows. I believe, one is easier to spot if you check the imgur filename.  The other, which I may be wrong about, is the need for a delay before moving the created gifs.

2_24 production build:
Code:
import csv, os, pyautogui, pyperclip, re, requests, shutil, subprocess, time, urllib.request, webbrowser
from datetime import timedelta, date
from os import rename
from tkinter import Tk

# start runtimer
startTime = time.perf_counter()

# set dates for links and new folder
today = date.today()
tomorrow = today + timedelta(1)
      
# learn to scrape 24 images 1 second at a time, yatta!
# 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(link)
    urllib.request.urlretrieve(link, 'download ({}).png'.format(number))
    number = number - 1
    time.sleep(3)

#delete the source code
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))
        number = number - 1
        time.sleep(3)
        print(link)
    
# delete the soure code
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)
print("Directory '%s' created" %directory)

# hot keys for confirming plugin to open, load, export, scale, export gif, gif2, quit, agree to not save
# bye, bye, batch (for now :)
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')

# uploading big gif and getting link to use later,
url = "https://api.imgur.com/3/image"
payload = {'name': '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)

# repurposing some code, that means define a function, right?
# 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()

# delete the link.txt
os.remove('C:/Users/Games/imgurlink.txt')

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']
for imgur in imgurlink:
    ibg = imgur

# big gif is moved
src = "C:/Users/Games/Postman/files/gif.gif"
dest = "C:/PyProjects/GMIP/2024/2-2024/"
shutil.move("C:/Users/Games/Postman/files/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")

# little gif is moved
src = "C:/Users/Games/Postman/files/"
dest = "C:/PyProjects/GMIP/2024/2-2024/"
shutil.move("C:/Users/Games/Postman/files/gif2.gif", dest)
rename ("C:/PyProjects/GMIP/2024/2-2024/gif2.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)

# only move numbered png files
for file in files:
    if os.path.isfile(file):
        if file.endswith(").png"):
            shutil.move(file, dest)  

# open websites to upload gifs
url3 = "https://www.talkimg.com/"
webbrowser.open(url3)

# pyautogui to the rescue
time.sleep(5)

# click start uploading
pyautogui.click(953, 590)
time.sleep(5)

# click file enter box
pyautogui.click(221, 479)
time.sleep(5)

# type name of small gif
pyautogui.typewrite("gif2.gif")
time.sleep(5)

# move selection to save
pyautogui.hotkey('tab')
time.sleep(1)
pyautogui.hotkey('tab')
time.sleep(1)
pyautogui.hotkey('enter')
time.sleep(5)
pyautogui.click(949, 645)
time.sleep(5)

# click mouse to copy the talkimg link
pyautogui.click(1276, 625)

imgtalklink = pyperclip.paste()

# 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}].{imgtalklink}.[/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
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 comments to code about talkimg, pyautogui.  phrasing

█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
DirtyKeyboard (OP)
Sr. Member
****
Online Online

Activity: 252
Merit: 459


Fly free sweet Mango.


View Profile
February 26, 2024, 07:59:29 AM
Last edit: February 26, 2024, 08:36:27 AM by DirtyKeyboard
 #20

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.  Huh  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. Cheesy  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.  Roll Eyes  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.  Smiley

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... Smiley  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
Code:
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

█████████████████████████████████████████████████            ▟██           ██████
██████████████████████████████████████████████        ⚞▇▇▋███▎▎()>       ████
█████████████████████████████████████████████████            ▜██           ██████
Pages: [1] 2 3 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!