Pages:
Author

Topic: My journey from user, to cyborg, to maybe coding a bot. - page 3. (Read 946 times)

sr. member
Activity: 114
Merit: 93
Fly free sweet Mango.
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.

sr. member
Activity: 114
Merit: 93
Fly free sweet Mango.
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.
copper member
Activity: 1386
Merit: 1481
Bitcoin Bottom was at $15.4k
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.
sr. member
Activity: 114
Merit: 93
Fly free sweet Mango.
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
sr. member
Activity: 114
Merit: 93
Fly free sweet Mango.
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
copper member
Activity: 1386
Merit: 1481
Bitcoin Bottom was at $15.4k
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.
sr. member
Activity: 114
Merit: 93
Fly free sweet Mango.
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",
        "/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!

sr. member
Activity: 114
Merit: 93
Fly free sweet Mango.
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",
        "/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
sr. member
Activity: 114
Merit: 93
Fly free sweet Mango.
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
Pages:
Jump to: