Twitch Follower Alert i.e. win prizes from giveaways!

Standard

While watching streamers on twitch.tv I noticed an abundance of channels doing “giveaways at n followers”. Wouldn’t it be great to win some prizes without watching 30 channels simultaneously I thought to myself.

  • Problem 1: I don’t have 30 monitors
  • Problem 2: I generally only tune in for tournaments and don’t have time to view so much media

Solution: Python + Twitch API Here is my solution and my face when it works:

TwitchFolloweAlert

TwitchFollowerAlert

JFLAP, XML and Python (COSC261 fix)

Standard

Last semester at University, I took a course based around ‘Formal Languages and Compilers’ aka COSC261. We had weekly quizzes to complete, which was great, but there was one task that always felt a lot more tedious than it needed to be: translating JFLAP diagrams to a transition table in to list of lists e.g. [ [ ], [ ] ] format, as required by the University’s quiz server.

I felt a couple stabs to the grade-book as I hastily submitted DFAs that worked perfectly on my local machine, but were rejected via the quiz server. The rejection was solely caused by mishandling of the data entry. As any geek would, I raged at the thought of mindless data entry and studied the implementation of JFLAP. It turns out that JFLAP saves as a .jff file, which does sound mysterious, until I inspected it in vim. Below is a screenshot of the inspection and the implementation.

dfa_parser

Sure enough, it was a neat XML representation. Have a look for yourself, the developers put a lot of effort into the formatting (thanks a lot, team).

$ vim yourJFLAPfile.jff

Once in vim, you’ll need to enter :q! to exit, yes include the colon. This quits without saving, as you probably don’t want to modify the file directly (i.e. likelihood of adding errors).

Recently I had been working on processing data-feeds, which the majority of which were RSS/XML based, so this was a breath of familiar air indeed. My implementation is merely a proof of concept and definitely encourage anyone with enough time to improve upon it! The output is currently a tuple (FROM, [TO, SYMBOL]). As a trivial exercise you’re welcome to convert this to a list of lists, so that the quiz server does indeed accept it.

I’ll leave challenge of interpreting the parsing as homework. The script and all directions are on GitHub: https://github.com/C-Kenny/DFA_parser_COSC261


Some of the issues I ran into were:

  • Parsing Epsilon
  • Withholding the frustrated knowledge of how many marks could have been saved

Future Aims:

  • Implement for NFA, currently it works great with DFA (I’ve already added the ability to process Epsilon and the entries for each node are not statically typed)
  • Build an implementation of the script that links to our schools variant of Moodle, so that students can upload the JFLAP files (be sure to watch out for that nasty XML).

Clean Up File Names Via Python

python_rename_CK
Standard

Today I would like to share a tiny script that I use to tidy my folders. As an example, I am generally not interested in the year the film was made e.g. BladeRunner(1982) and prefer it listed as BladeRunner in my films directory. This script will do just that, modify the file names of files, without changing the internal contents. Here is an example of the script in action:

python_rename_CK That definitely looks better, to me at least. Here’s a run-down of what just happened and how:

  1. ls – displays the basic (non-hidden) contents of a folder
  2. python rename_CK.py && ls – This runs the python script on the folder it is placed in. For me, it was my working folder i.e. ~/Documents/…/brackets_backup then it uses && to run multiple command on line line, followed by ls to view the results
  3. Results displayed

The python script can be found here: https://github.com/C-Kenny/batch_file_renamer_python


Future Plans:

  • Add a recursive modifier, so that it is able to go inside various sub-folders and continue the good work
  • Rewrite in C for fun
  • Make good use of the script via ssh

Python Solves Group Financials

Python Solves Group Living Finances
Standard

Are you looking for a way to simplify your flat’s finances? Well I have the right script (i.e. small program) for you! To run this script you will need the following:

  • Programming Experience Required: None
  • Python 3 or higher installed on your machine
  • Access to your shared bank account via internet banking (don’t worry, this script won’t need your credentials, just the transaction data to sort out the mishaps!)

I’m currently studying towards a bachelor science in Computer Science and Psychology. Throughout my studies I have chosen to experience flatting i.e. living with a bunch of friends. This has always been a great experience, however there’s one topic that tends to be avoided to keep people happy:  money.

If you’ve had similar experiences in the past or are experiencing this right now then please keep reading, as this script can help you logically solve them. I would like to point out that I built this script for my own programming pleasure and it is very likely that you can get the same result a lot faster by using a tool you’re comfortable with.

This script is open-source and I promise it doesn’t send your valuable information /or finances across the internet. If you don’t trust it, ask someone with programming experience to take a look at it or don’t use. Better to be safe 🙂

This script requires a few things:

  • The .csv file which can be downloaded from your bank’s website
  • The Python script
  • Very basic command line ability (I will explain everything)
  • Python 3 to be installed

Regarding the command line, I’ll be attacking this from a Windows perspective, as I’m assuming anyone who has a distribution of Linux is well versed with the terminal. Just be careful with the direction of the slashes…

Download the .csv file and the .py script to a place you where you can find it. e.g. C:\Users\USERNAME\Documents\Python

It will also be helpful to rename the file to something smaller and that contains no spaces.
e.g. bankaccount_2014.csv

Now, using the file explorer, locate to where you’ve saved the .csv file and the .py file. It should look like this:explorer_cli_python_csv

Now we need to open up the Windows command line. Don’t worry, I like walk you through this and we will be using minimal commands. As a side note the command line can be very useful, so if this example feels fun, head over to your favourite search engine and do some research!

Now, hold down [SHIFT] on your keyboard, right click the folder and select ‘Open Command Window Here’

A window will open up with a very limited visual interface, but it’s very powerful once you know how to use it!

C:\Users\YourUsername\YourFolderPath is where you have opened the command line. To check that everything we want is there. Type dir /b and then press enter. What you should now see printed to the command line is all the files in the current directory, the /b is an argument given to display only the minimal presentation of files. If you’re interested try “dir” own it’s own and observe the difference.

Quickly we’ll check that you have Python 3 installed and accessible. Type python and press enter. If it displays Python 3.x.x, great! Press [CTRL] + [z] to end the Python interpreter. *If it displays “python is not recognized as a internal or external command, …” then you need to go install Python and add it to your path (The GUI installer has a drop-down entry for this)

Almost there! Below I will use XXX as a placeholder for the name of your .csv file. If that confuses you, rename the .csv file to XXX.csv (however, this might seem dodgy when you look back through your documents…)

To run the script on your data, type: python shared_bank.py XXX.csv 

If you’re rushing to look at the result, type: output.txt and press enter! This should open up the output of the script in your standard text editor (probably Notepad or Word, for most). Great, now go analyze those mischievous transactions and the fairness of everyone’s contributions. Stop here if you’ve had enough of the command line and just want to get to the number crunching!

Yay, you’ve made it. If you’re interested in attempting to understand the code, have a read over at GitHub,I originally made this script just for myself then I had friends complaining about similar problems, so I adapted it and sent it off to them. The “>” writes all the print calls to an output file. This should have been placed into the script, however I prefer to send the output through many programs in my spare-time. In the GNU/Linux terminal, this is referred to as ‘piping’ which uses the | key

I’ve now changed the script, so that it writes a file on it’s own.

It has been tested with Westpac and KiwiBank .csv files. I’m sure other banks format their data differently, as I couldn’t find a universal standard anywhere. Comment if the script doesn’t work on your particular .csv file and I’ll do my best to adapt it to your situation! You won’t need to give the .csv file, just one row (change the people’s names and figures at your will, it’s just the columns that are important)

Future Plans:

  • Optimize the code, so it runs more efficiently. E.g. use less nested for-loops, create a list for original name, upper and lower at the beginning instead of on the fly (i.e. pre-processing)
  • Add a Java GUI on-top of the Python code, so that the user can drag and drop their .csv file into the application without having to open up the command line
  • Format the output nicely (i.e. line-by-line) and possibly convert back to readable .csv
  • Create a ‘smarter’ version, that dynamically locates the name/date/input/total/description fields and can run without the user having to input the people’s names (dictionaries will be key here)

Hope it helps! Leave a comment below if you need assistance or would like to show your appreciation.
Farewell,
Carl