Category Archives: Python

Music Player progress

Been working on the Media Player, from the wxPython widget, MediaCtrl. I am pretty sure I’ve written at least one post a few weeks ago about how much trouble I had to go through just to get the thing working… here But luckily, since then I haven’t run into much trouble, as far as wxPython goes.

Hit the jump for an update on some of the issues I’ve been dealing with.

Continue reading Music Player progress

How to find your Public-facing IP with Python, requests and BeautifulSoup

In this entry, we’re going to look up what our public facing IP address is, using the Python modules, re, requests and BeautifulSoup. It’s going to send a request to whatismyip.com with requests, then we’re going to parse the returned HTML in BeautifulSoup, so we can break it up, and navigate through it a lot easier, and then finally, use re to grab the IP address and print it to the screen.

Hit the jump for the tutorial!

Continue reading How to find your Public-facing IP with Python, requests and BeautifulSoup

wxPython MediaCtrl Tutorial

This is just a short post to explain something I had a hard time understanding: How to get the media player working for Windows 7, (64bit, if that matters here, I’m not actually sure).

I never fully understood what it took to start playing a song, since I assumed that I needed to just load the song into the media player ctrl, then play it, but there was a subtle thing I needed to do as well, and that was to catch the event EVT_MEDIA_LOADED.

before I could sucessfully play the mp3, as well as change the backend of the mediaCtrl to WMP10, instead of leaving it as default. The part that really through me for a loop was that all the docs I had read on this, just loaded and then played the song right away. Seems like there’s a bug somewhere that doesn’t catch that event on Windows 7.

Anyways, here’s a simple script, after the jump, that lets you play one single song, hardcoded into the file, if you want to change the song to play, you’ll have to change the filepath in the code.

Continue reading wxPython MediaCtrl Tutorial

reddit API Part 1: Logging In

Welcome to the first part of my reddit API tutorial for Python 2.7! In this short tutorial we will just focus on signing in to reddit’s API so we can interact with it later.

Hopefully you’ve read the introduction on the modules we’ll be using found here, so if you’re a beginner, you won’t be that lost.

Before we start, I am just going to give you a brief overview of what we are going to do: create a python DICT that has your reddit account name and password in it, so that we can send it to the API with our request. Then, armed with our modhash that we received from the API, we can move on to interacting with reddit, which we’ll check out in the next part of this tutorial!

Tinypaste of the entire code as seen at the bottom of the page

Hit the jump for how to login to the reddit’s API. As usual, the full code will be shown at the end of this page.

Continue reading reddit API Part 1: Logging In

Imgur API part 2: Downloading a Gallery

This is the second installment of my Imgur API: ‘How to entire download Imgur Galleries’. Check out part 1 here in case you missed how to log into the API and upload an image!

I’m actually sort of cheating here, because we don’t actually need to use the API at all here, if we don’t want to. That is because we’re only going to deal with the galleries that are built from the images submitted to reddit. This means after you’re done with this tutorial, you’ll be able to just set the script to a given subreddits name, and grab all the images that have been submitted to /r/aww or /r/wallpapers.

I will be writing another tutorial soon for galleries and albums unrelated to reddit.com as well as grabbing gallery information, such as the title and other descriptive things like that, but that’s less related to the actual downloading of the gallery, which is what we’re interested in today!

Please note that I’m working with Python 2.7 on Windows 7 64-bit, so you might have to modify the code slightly to accommodate for your platform, or OS.

Anyways, hit the jump to get started!

Edit: reddit user: easttntoppedtree caught that it maxes out at 56 images, so you’ll have to add /page/PAGENUMBERHERE.json to the end of the url to get the next 56 images like so: http://imgur.com/r/scarlettjohansson/top/page/1.json’ while keeping in mind that 0 (zero) is a valid page number

Tinypaste link for the full working code, as seen at the bottom of the page

Continue reading Imgur API part 2: Downloading a Gallery