This Website Is Terrible

As you can probably see, this website is no longer (and never was) cutting edge. Its WordPress theme was written in about 1 hour in 2010 or so (note the IE 6 conditional template tags, as well as the manic use of tabs in the page’s source). The site had two purposes: one, to incorporate coprophilic monkeys; and, two, to dissuade any friends from asking me “hey, can you build my website for me?” Dimpled Chad, a web project that took over my life in 2012, too, was based on kludgy procedural-only PHP scripts.

Nonetheless, I’m trying to keep my knowledge of programming up-to-date. My newest website (in production) is designed in Bootsrap (which, when combined with WordPress, is bloated and slow, but hey–cutting edge!) and adheres to the best object-oriented practices. Most of what I do programming-wise now is in R (which is replacing alternatives because new versions of IBM SPSS cost ungodly sums of money). I also made a New Year’s resolution to replace the language I use in my personal programming projects from C++/Perl/PHP (each close to my heart) with Python owing to the demands of the job market. Python is sleek, efficient (it requires no interpretation layer when properly deployed on servers)–but ugly and charmless. I will mourn PHP’s idiotic but lovable string functions.

I wrote my first useful Python script (which stripped photographs of every Congressperson from the House website) last night and ran it via old-fashioned CGI. My second New Year’s resolution, however, is that all my scripts must always output the last line seen here:

#!/xampp/python/python

# includes
import csv
import os
import urllib.request

# header
print('Content-Type: text/plain\n')

# directory
out_dir='downloads'
try: 
    os.makedirs(out_dir)
except OSError:
    if not os.path.isdir(out_dir):
        raise

# candidate object
class Candidate:
    def __init__(self,vickrey_id,congress_bio_id):
        self.download_file='http://bioguide.congress.gov/bioguide/photo/'+congress_bio_id[0]+'/'+congress_bio_id+'.jpg'    
        self.upload_file=out_dir+'/'+vickrey_id+'.jpg'
    def download(self):
        print('Downloading',self.download_file,'...')
        try:
            with urllib.request.urlopen(self.download_file) as response,open(self.upload_file,'wb') as out_file:
                data=response.read()
                out_file.write(data)
        except:
            print('Could not download',self.download_file)        

# load candidates
candidates=[]
with open('bios.csv','r') as csv_file:
    csv_handle=csv.reader(csv_file,delimiter=',',quotechar='"')
    next(csv_handle)
    for i in csv_handle:
        vickrey_id,congress_bio_id=i
        if(congress_bio_id!=''):
            candidates.append(Candidate(vickrey_id,congress_bio_id))

# download images
for i in candidates:
    i.download()

# done!
print('I ATE THE BONES!');

Tomorrow I write my first script for an academic project. Rest assured, the bones will be eaten.

About cvickrey

Clifford Vickrey spends his days confounding the wise.
This entry was posted in I ate the bones. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *