2021 November
-
Some notes on posting to Mastodon via their HTTP API using Python. The backend of this site uses similar code to enable automated syndication to my Mastodon account. Creating an access token Go to your mastodon preferences (it's the gear icon above the search bar in the web interface) and click Development. (Or go to [yourservername]/settings/applications) Click "New Application". Specify application name. Default permissions should be fine. Save. Click your application name in the grid on the Development page. Your access token will be in the top part of the screen. Posting a status (or as they call it, a
2020 January
-
In a bid to reduce the number of webapps actually running on my server (for resource consumption reasons), I decided to migrate a small Flask app I had and merge into this larger Django app where I have a lot of my personal data tracking stuff. The Flask app was small enough, mostly containing backend support for this blog (like search and comment submissions) and some Twitter things. The migration was straightforward, taking around half a day, most of that was wrangling with Twitter API rate limits. It got me thinking, why did I build this using Flask in the
2019 August
-
Back when I was still learning Python in 2008, one of the first "fun" scripts I wrote was a text generator using Markov chains. I'd run it against all the chat logs I had with people at work and serve the results from a webserver on my computer. THe results were often amusing and sometimes hilarious. Since I've been going through my old scripts lately, I thought I'd update that script to Python 3 (read: add parentheses around print params and use pathlib) and run it against all the posts on this here site. I added the script to my
-
Ever since I started learning Python back in 2008ish, I've been using it as my primary scripting language for various tasks such as processing log files, organizing my own file system, processing stuff on this blog, and so on. A lot of it is basically moving files around. In the days of Python 2, that involved a lot of imports of different libraries like os, shutil and glob. It can become a bit messy with so many imports, and I often can't remember which import I need for a particular case and end up having to search for the documentation
2019 February
-
A while back I started a Twitter trivia bot as a weekend project. That bot is still up and running on Twitter, you can check it out there! But today, I thought I'd write about the answer-checking mechanism used by the bot. It was a bit interesting to me because it was the first nontrivial use I had for Django's unit testing framework. I'm not too keen on unit testing web functionality (something I still have to learn), but this seemed an appropriate first use of a unit test framework for several reasons: the bot had to be able to
2018 October
-
Ten years ago this month, I started studying Django by trying to build my own blog application. I found the code lying around while I was going through some backups lately. It's way out of date, it uses an early version of django. I thought of bringing it up to speed, but that didn't seem practical. Instead, for archival purposes, I cleaned it up a bit and uploaded the code to a github repo. (Helpful github immediately warned me that having a very old version of Django was a security risk lol). There's a lot more information in the README.md
2017 March
-
I've been hesitant to try Python 3.x because it's not backward compatible with Python 2.x which I've been using for scripting since forever. But recently I found out that since Python 3.3, they've included a launcher in the Windows version that supports having both versions installed. You can use the launcher to specify the Python version to use at the command line (it defaults to whichever version was installed first): Even better, the launcher will recognize a header in your .py files that can specify which version of python to use: #!/usr/bin/env python3 If the launcher sees this header, it
2017 February
-
I had been meaning to try writing a Twitter bot for a while now. I figured a trivia bot would be pretty easy to implement, so I spent some time a couple of weekends to rig one together. It's (mostly) working now, the bot is active as triviastorm on Twitter, with a supporting webapp deployed on https://triviastorm.net/. The bot tweets out a trivia question once every hour. It will then award points to the first five people who gave the correct answer. The bot will only recognize answers given as a direct reply to the tweet with the question, and
2017 January
-
So the other day I was reworking a Python script that I had been using for years on my home PC to manage and categorize some downloaded files for me. This time I wanted to add some smarter behavior to make it more able to figure out when to group files into folders without constantly needing manual intervention from me. To do this, I needed to persist some data between runs -- so that the script remembers how it categorized previous files and is able to group similar files together. Now since my software development career has largely been as
2011 August
-
💬 Reply to :
Earlier today i was thinking of writing a python script to detect duplicate mp3s, you might want to try that. There are existing programs to do it, but they all seem terrible!
2010 October
-
In Python, say I have a string that contains the name of a class function that I know a particular object will have, how can I invoke it?
That is:
obj = MyClass() # this class has a method doStuff() func = "doStuff" # how to call obj.doStuff() using the func variable?
-
💬 Reply to :
Split your processing into multiple threads. Your particular i7 should be able to support up to 8 threads in parallel.
2010 July
-
One of the responses has a nice discussion on the state of python web frameworks.
2010 June
-
Is there any Python library that allows me to parse an HTML document similar to what jQuery does?
i.e. I'd like to be able to use CSS selector syntax to grab an arbitrary set of nodes from the document, read their content/attributes, etc.
The only Python HTML parsing lib I've used before was BeautifulSoup, and even though it's fine I keep thinking it would be faster to do my parsing if I had jQuery syntax available. :D
2010 January
-
💬 Reply to :
urlpatterns = patterns('',
(r'^salaries/employee/$', list_detail.object_list, 'employee_info'), )The third item in the tuple needs to be a dictionary, not a string. Try removing the single quotes around employee_info:
urlpatterns = patterns('', (r'^salaries/employee/$', list_detail.object_list, employee_info), )
2009 December
-
💬 Reply to :
You will need a better editor than Notepad. With Notepad, use Save As..., and type "helloworld.py" in the dialog, including quotes so that the file extension is .py instead of .txt
-
💬 Reply to :
You can have an array of 3-item tuples.
arr = [ (1,2,3), (4,5,6), (7,8,9)] for (k, v, x) in arr: # do stuff
2009 September
-
π Andy McKay's blog via delicious
-
π Django snippets: Facebook shell via delicious