Showing posts with label parking. Show all posts
Showing posts with label parking. Show all posts

Thursday, September 17, 2009

Google Fails Me!

My street cleaning program appears to be working just fine, except for the fact that for some reason Google never sent me either of my SMS reminders this morning. I looked at the calendar and they're set up and everything; I just never got the message. And it worked perfectly on Monday!

It cost me a $115 ticket for double parking, though thankfully my neighbor alerted me before they could tow my car.

Clearly, I'll need a text-messaging system more robust than reminders in Google calendars. AppEngine will let me set up cron jobs (nullus), which I should then be able to use to trigger a message via Zeep.

Friday, September 4, 2009

Okay, Now I'm Really Done

Finished porting my street cleaning reminder program to Python for AppEngine, where it seems to be working fine. One unfortunate thing about moving the original desktop C# 3.5 code to ASP.NET 2.0 was that I had to replace all my nice Linq queries with regular loops, so being able to make use of Python features like tuples and list comprehensions was enjoyable.

Here is the code, with my personal identification information removed, and which I hereby release into the public domain:


import cgi


from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app


import gdata.service
import gdata.calendar
import gdata.calendar.service
import atom.service
import gdata.alt.appengine


import string
import time


class Cleanendar(webapp.RequestHandler):
  
  def __init__(self):


    manager = CalendarManager()
    self.commands = { 'n': manager.north, 's': manager.south, '': manager.clear }




  def post(self):


    if self.request.get('event') == 'MO':
      if self.request.get('uid') == MY_ZEEP_UID:


        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write(self.process_command(self.request.get('body').lower()))
        return


    self.response.clear()
    self.response.set_status(400)




  def process_command(self, body):


    if body in self.commands:
      self.commands[body]()
      return ''


    else:
      return 'Bad command [' + body + ']'






class CalendarManager:


  def __init__(self):


    self.service = self.get_service()
    (self.calendar, hcalendar) = self.get_calendars(self.service)
    self.id = self.calendar.id.text.split('/')[-1]
    self.holidays = self.get_events(hcalendar.id.text.split('/')[-1])


    self.prefix = 'Cleanendar: '
    self.begin = time.strptime(time.strftime('%Y%m%d', time.localtime()) + '1230', '%Y%m%d%H%M')
    self.end = time.strptime(time.strftime('%Y%m%d', time.localtime()) + '1400', '%Y%m%d%H%M')
    self.daynames = ['Mo','Tu','We','Th','Fr','Sa','Su']




  def get_service(self):


    service = gdata.calendar.service.CalendarService(MY_GOOGLE_ID, MY_GOOGLE_PW, MY_APP_ID)
    service.ProgrammaticLogin()
    return service



  def get_calendars(self, service):


    feed = service.GetAllCalendarsFeed()
    calendar = None
    holidays = None
    for i, c in enumerate(feed.entry):
      if c.title.text == "Cleanendar":
        calendar = c
      elif c.title.text == "2009 NYC Alternate Side Parking":
        holidays = c
    return (calendar, holidays)




  def north(self):
    self.set_days([0,3])




  def south(self):
    self.set_days([1,4])




  def clear(self):
    events = self.get_events(self.id)
    for i, e in enumerate(events.entry):
      if e.title.text.startswith(self.prefix):
        self.service.DeleteEvent(e.GetEditLink().href)




  def set_days(self, days):
    self.clear()
    self.add_event(self.make_event(self.begin, "Move car", days))
    self.add_event(self.make_event(self.end, "Move back", days))



  def get_events(self, id):
    return self.service.GetCalendarEventFeed('/calendar/feeds/' + id + '/private/full')




  def make_event(self, t, desc, days):
    event = gdata.calendar.CalendarEventEntry()
    event.title = atom.Title(text=self.prefix + 'Street cleaning')
    event.content = atom.Content(text=desc)
    event.recurrence = self.make_recurrence(t, days)
    event.reminder = self.make_reminder()
    return event




  def add_event(self, event):
    return self.service.InsertEvent(event, '/calendar/feeds/' + self.id + '/private/full')




  def make_recurrence(self, t, days):
    data = ('DTSTART;TZID=UTC;VALUE=DATE-TIME:' + time.strftime('%Y%m%dT%H%M%S', t) + '\r\n' +
      'DURATION:PT5M\r\n' +
      'RRULE:FREQ=WEEKLY;BYDAY=' + string.join([self.daynames[d] for d in days], ',') + ';' +
      'UNTIL=' + time.strftime('%Y', t) + '1231\r\n' +
      'EXDATE:' + string.join([time.strftime('%Y%m%d', d) + time.strftime('T%H%M%S', t) for d in self.make_exclusions(days)], ',') + '\r\n')
    return gdata.calendar.Recurrence(text=data)




  def make_exclusions(self, days):
    e = []
    for i, h in enumerate(self.holidays.entry):
      for t in [time.strptime(w.start_time, '%Y-%m-%d') for w in h.when]:
        if t.tm_wday in [0,3]:
          e.append(t)
    return e




  def make_reminder(self):
    return gdata.calendar.Reminder(minutes=10, method='sms')




application = webapp.WSGIApplication([('/', Cleanendar)],
                                     debug=True)


def main():
  run_wsgi_app(application)


if __name__ == "__main__":
  main()

Thursday, September 3, 2009

Victory!

Zeep did indeed do what I wanted, and I found a site that hosts ASP.NET for free for 90 days, so I can now set my street cleaning days from my phone!

So if I have it set for the South side of the street (reminding me to move the car on Tuesdays and Fridays), my calendar looks like this:

Week from a Google calendar showing reminders to move the car on Tuesday and Friday

And then I go somewhere and when I come back I park on the North side. So I text "cleander n" to 88147, and the reminders jump to Mondays and Thursday, (excluding any day in the green holiday calendar):

Same week with reminders to move the car on Thursday, with none on Monday because of Labor Day

Zeep recognizes my phone number and uses the "cleander" string to route everything following it to my ASP.NET page in an HTTP POST request.

When the message gets to my site, the "n" or "s" populate the calendar with reminders on the appropriate days, an empty text clears the calendar completely (useful for going on vacation), and anything else will result in an error response.

I've saved "cleander n" and "cleander s" as message templates on my phone, so now any time I park it's just a few quick clicks.

Of course it will all fall apart in 90 days when my AspSpider account is deleted, but in the meantime maybe I'll be able to find some other free hosting option: all I need is to be able to run some sort of code in response to a POST request; the code is in C# right now, but it's short, and Google has APIs for Python and PHP and Java and whatnot as well, so I should be able to find something that works.

Update: Okay, Google's AppEngine will totally do what I need. I'll try it out tonight. It's fun and amusing to cobble together a baroque solution like this all to accomplish something that would take no effort at all if stupid T-Mobile would let me run a program on my phone in the first place. but also sort of depressing that I have to.

Update Deuce: This makes me feel a little better...apparently I'd have to do something similar on the Apple phone, as they don't provide a calendar API. Android does, but it's undocumented, though I would assume they make syncing with Google Calendars pretty easy so maybe it's less work. Palm gets it right.

Wednesday, September 2, 2009

Nerdery

So after being stymied (is that anti-Semitic?) in my attempt to run an alternate-side parking reminder program on my phone, I finally decided to just write a desktop version:

Window for selecting side of street

It sets up recurring events for the beginning and end of street cleaning hours, with an SMS reminder 10 minutes before, and excluding any days listed on a user-specified "holidays" calendar.

So, almost fine. I'll still need to remember to run the program after I get home and park my car, whereas with the mobile application I could have done it right from the phone. But text reminders and not having to set alarms twice a day on street cleaning days gets me 80% of what I wanted.

Something I definitely want to look into is the possibility of using an SMS web gateway to control a similar program running on a web server. I don't know if there are any free web hosts that allow you to run .NET or Python programs...you'd think that kind of thing would be de riguer in this day'n'age, but you could fill a wikipedia with what I don't know about internets hostering.

Update: I forgot to specify that when I wrote "sets up recurring events" that I meant it adds them to a Google calendar. That's where I got the idea to exclude holidays, because there's already a public calendar I subscribe to with all the street cleaning holidays. I also neglected to include the name of the project, which is "Cleanendar" and makes perfect sense.

Thursday, July 10, 2008

Variable-Rate Parking

Streetsblog on DOT's plans for variable-rate parking. I have to say, the figures they're talking about (increasing rates from $1 an hour to around $2.50) strike me as less extreme then what I would expect the market to bear, but it sounds like they recognize that and are just starting small to see what effects it has. Good move.

Tuesday, April 15, 2008

Deference

I read the responses to the recent Feministe Feedback question on Being a Feminist Boyfriend with a lot of interest, and I was surprised that Amanda at Pandagon took issue with the first comment, which suggested that "deference is a privileged person's best friend." I had actually thought that a really succinct way of putting my thoughts on the issue.

It turns out I was just mistaken on the definition of "deference." There are a couple different ones, but they all seem to hinge on being "courteous and respectful" in "submission," or "yielding," to another. Sounds a lot like chivalry, and I agree, totally inappropriate.

But I think there is a related attitude, on the part of anyone in a discussion with someone over whom they enjoy privilege, that it is important to have. And that's to never assume that "awareness" of the issue at hand can ever substitute for that issue as seen by someone who must experience it first-hand.

The flawed behavior the attitude addresses can manifest in two ways, dismissal and self-righteousness. The dismissive version is basically, "look, I know all about feminism, and you're overreacting." And the self-righteous version is some variation on "I know all about feminism and you're being a bad feminist." In either case, the privileged person is claiming that their theoretical knowledge of oppression should trump another's actual experience of that oppression.

(I'm sticking with gender and feminism here since that's the discussion that brought it up, but the same dynamic obviously applies to any sort of societal oppression.)

By dint of the very privilege that's at issue, the privileged person's voice is going to have more weight behind it, and so it is even more vital that the privileged person takes other voices seriously. Which is what I would have wanted to call "deference," since one "defers" to the relevant experience of another. But it's not really "deference" because you're not doing it out of "respect and courtesy," but because they are in a position where they are more likely to know what the fuck they are talking about.

It's like when you're trying to squeeze into a tight parking space and your friend hops out to help direct you in from the sidewalk. You don't follow their instructions out of "respect" or "courtesy," but because they are positioned such that their perspective is more likely correct. No matter how sure you are that you're about to scrape the car on your left, if they assure you that you have more room, then you trust them. Unless you have reason to think they're trying to make you crunch your fender, you have to acknowledge that they're in the best place to judge the relevant distances.

As someone who has read a little in feminism, and who tends to didacticism in all things (but who has lived not one second as a woman under patriarchy), my tendency is to err on the "self-righteous" side (though I have certainly had my share of dismissive moments as well). But obviously, whatever little use I may be lies in being able to speak about oppression to other privileged people, from a shared position of privilege. Discussion with others should not primarily be about making myself feel good about my "awareness"; rather, it is a good time to listen, and should be valued as the learning opportunity it is.