Table of Contents

1 What is this script?

This is a script to generate RSS from social media websites like librarian, mastodon and teddit. I would like to analyze this code and give some of my thoughts about it.

2 Imports

Here are my imports for the script. The first one is very important because it imports TK so I actually have a GUI program. The second one is subprocess which I only use to run a basic shell command.

# Import all of tkinter GUI stuff
from tkinter import *
# Run shell commands
import subprocess

3 Variables

These are a variables for how the TK is run. I have no clue how that works. Then I have a variable for the browser.

# Important variable
root = Tk()
browser = 'c:\\users\\stanl\\appData\\local\\bravesoftware\\brave-browser\\application\\brave.exe'

4 Name

This is the name of the program

# Name of window
root.title("RSSgenerator")

5 Icon

I ended up not having a icon because it was dificult for users of the script to use the icon. Also icons are kinda bloat.

# Set the icon
# root.iconbitmap('freedomerss.ico')

6 Window size

Here I say how big I want the the window to be when the app is ran.

# Window size
root.geometry('650x650')

7 COLORS

Colors are very cool. I just added a dark and classy background color so the user doesn't stare at a blaring WHITE.

# Color
background_color = '#1A1919'
root.configure(bg=background_color)

8 Label

This label is spawned in to show the user what the script is.

# Title properties
title = Label(root, text="----- \n RSS Generator \n ----- ",
	      bg=background_color,
	      fg='#ffffff',
	      font='20')

9 Title pack

This is important for actually putting the title on the screen.

# Place title on screen
title.pack()

10 Help.

Users don't know how to use the program so this teaches them.

# Help info
help_ = Label(root, text = "Instructions: \n Enter a freedom respecting social media: \n mastodon - Twitter alternative \n teddit - Reddit viewer \n librarian - LBRY viewer \n \n Now enter a link you want the RSS of and it will open in your browser. \n ----- ",
	      bg = background_color,
	      fg='#ffffff',
	      font='20')

# Place help info on screen
help_.pack()

11 THE ACTUAL THING

This does many things first is a label.

The label tells the user what the box they entering in does.

# Mastodon label
label_mastodon = Label(root, text = "Put a Mastodon url:",
		       bg = background_color,
		       fg = '#ffffff',
		       font='10')
# Place mastodon label on screen
label_mastodon.pack()

This is the actual entry box.

# MASTODON
feild_mastodon = Entry(root, width=50)
feild_mastodon.pack()

The button can run functions. With this I am able to get what the user inputs and print out a message that it was copied. I also store in a variable the new rss link value. Then using the tkinter tools I can copy stuff to the clipboard. Finally I use subprocess to launch the link in browser. This helps the user make sure the rss link is correct.

def click_mastodon():
    new = feild_mastodon.get() + ".rss"
    myLabel = Label(root, text=feild_mastodon.get() + ".rss is copied!")
    myLabel.pack()

    # Copy to clipboard
    root.clipboard_clear()
    root.clipboard_append(new)
    # Run the browser variable with the new url arg.
    subprocess.Popen([browser, new])

button_mastodon = Button(root, text="Enter", command=click_mastodon)
button_mastodon.pack()

12 COPY, PASTE and SUBSTITUTE

I took all that code and copied pasted and substituted to the correct social media platform. i also put the specific text to get the rss of the given link.

# Nitter label
label_nitter = Label(root, text = "Put a Nitter url:",
		       bg = background_color,
		       fg = '#ffffff',
		       font='10')
# Place nitter label on screen
label_nitter.pack()

# NITTER
feild_nitter = Entry(root, width=50)
feild_nitter.pack()

def click_nitter():
    new = feild_nitter.get() + "/rss"
    myLabel = Label(root, text=feild_nitter.get() + "/rss is copied!")
    myLabel.pack()

    # Copy to clipboard
    root.clipboard_clear()
    root.clipboard_append(new)
    # Run the browser variable with the new url arg.
    subprocess.Popen([browser, new])

button_nitter = Button(root, text="Enter", command=click_nitter)
button_nitter.pack()

# Librarian label
label_librarian = Label(root, text = "Put a Librarian url:",
		       bg = background_color,
		       fg = '#ffffff',
		       font='10')
# Place librarian label on screen
label_librarian.pack()

# LIBRARIAN
feild_librarian = Entry(root, width=50)
feild_librarian.pack()

def click_librarian():
    new = feild_librarian.get() + "/rss"
    myLabel = Label(root, text=feild_librarian.get() + "/rss is copied!")
    myLabel.pack()

    # Copy to clipboard
    root.clipboard_clear()
    root.clipboard_append(new)
    # Run the browser variable with the new url arg.
    subprocess.Popen([browser, new])

button_librarian = Button(root, text="Enter", command=click_librarian)
button_librarian.pack()

# Teddit label
label_teddit = Label(root, text = "Put a Teddit url:",
		       bg = background_color,
		       fg = '#ffffff',
		       font='10')
# Place teddit label on screen
label_teddit.pack()

# Teddit
feild_teddit = Entry(root, width=50)
feild_teddit.pack()

def click_teddit():
    new = feild_teddit.get() + "?api&type=rss"
    myLabel = Label(root, text=feild_teddit.get() + "?api&type=rss is copied!")
    myLabel.pack()

    # Copy to clipboard
    root.clipboard_clear()
    root.clipboard_append(new)
    # Run the browser variable with the new url arg.
    subprocess.Popen([browser, new])

button_teddit = Button(root, text="Enter", command=click_teddit)
button_teddit.pack()

13 RUN

The final thing is to run the TK stuff.

# Run stuff
root.mainloop()

14 Conclusion

I had a bunch of fun writing this script. I don't think it serves a purpose for many people. But I think it serves a purpose for myself in the off chance I want to add someone to my rss list.

I hope you learned something new. The script is available on my codeberg.

Created: 2021-11-10 Wed 20:57

Validate