Sorry for failing to post on this blog. Hackerspacekl is going to host a python meetup this weekend!!!
This is python monthly meetup. This time we going to have it in here. This time we going to have a free flow event.
We will start with a talk, to be confirmed. Then a series of knowledge sharing, not limited to talk, and show and tell of your project done in python.
Talk that we have confirmed is
- Dexterity on Plone by either kagesenshi / kaeru
- Using elasticsearch with python by yours truly
- Django related topic by renyi
If you drive I recommend that you share a car, if on public transport, take a LRT to Taman Bahagia, and that Bus 626 to uptown, or take a taxi from there.
House rules applies, non members can’t use the soldering iron or the components. But they can use the room. But we are python meetup, so we definitely not going to need that.
The event detail is in http://www.eventbrite.com/event/3194836843
As usual my contact is
016 206 5780
email sweester at gmail dot com
Share this article
The remote control part of the robot already done, now to control it. Because I am out of component. So I decide to write a program to do so. The control program uses python, and it control via serial interface to the arduino, without the microntroller.
Python have many stuff in their standard library, but they don’t have a serial library. On the other hand, python community have created many library that is not in the standard library, pyserial is one http://pyserial.sourceforge.net/. To install it, just use
pip install pyserial
The library is very easy to use too. You need a sleep because sometime the arduino will drop the command if you send it too fast. So just use sleep as a delay. The serial port on windows it is comN, on the constructure replace ‘your serial port’ with a number without quote, it could be 0 for com1, etc. On linux you can specify the path, ‘/deve/ttyUSB0′ or 1 or what not.
import serialimport datetime.time as times = serial.Serial('your_usb_serial_port') time.sleep(2) s.write('serial command') s.close()
Essentially just 4 line minus import just to send serial command.
To make it fancy, I just bundle it with tkinter library for UI, which is part of the python standard library.
from Tkinter import * import serial import time class RobotUI: def __init__(self,master,port): self.port = port frame = Frame(master) frame.pack() self.forward_button = Button(frame,text="Forward",command=self.move_forward) self.forward_button.pack(side=TOP) self.backward_button = Button(frame,text="Backward",command=self.move_backward) self.backward_button.pack(side=BOTTOM) self.left_button = Button(frame,text="Rotate Left",command=self.rotate_left) self.left_button.pack(side=LEFT) self.right_button = Button(frame,text="Rotate Right",command=self.rotate_right) self.right_button.pack(side=LEFT) def move_forward(self): print "forward" self.move_('w') def move_backward(self): print "backward" self.move_('s') def rotate_left(self): print "left" self.move_('a') def rotate_right(self): print "right" self.move_('d') def move_(self,direction): s = serial.Serial(self.port) time.sleep(2) s.write(direction) s.close() root = Tk() app = RobotUI(root,2) root.mainloop()
Again the code for the controller can be found here https://gist.github.com/1378327
Now the robot is complete. And can be used. The last post, is on newsoftserial library for arduino. Not directly related to the robot. I experiment on it as I build it.
Share this article
Migrating from Plone to WordPress is not quite as straightforward as it may seem. In fact, it was quite a PITA. One of the factors for this was that none of us (except for @kagesenshi) have deep technical expertise on the innerworkings of Plone, or Zope. There was one solution, but reading through it, I know it would be a PITA.
So I decided that the best solution would be to parse Plone’s RSS feed and import them to WordPress’ MySQL database. This seems to be the most sensible, effective and headache free solution – provided that your Plone entries (articles, news, etc) combined are not in thousands.
The first thing that you need to do is to aggregate the entire Plone site. The steps to do this is well documented here.
The RSS by default will publish only 15 items. You have to change the RSS’ setting to, well, a very large number if you want to parse all the contents. This can be done by navigating to
synPropertiesForm of the Plone site.
So now you will have all the site’s content in RSS. Parsing the RSS is easy. My first attempt was to use ElementTree, a library that I always use whenever dealing with stuff XML-ish. Apparently it didn’t work properly, so I used feedparser instead.
Here’s a snippet of the code that does the job. This code reads a RSS file. feedparser can also retrieve the RSS remotely.
import feedparser import os import sys import MySQLdb as mdb # get this from the db # post_author id # mel => 1 # sniffit => 2 # klks => 3 # apparently unicode is not handled properly eventhough uft8 is aleady set, so edit the RSS file and remove Unicode chars first if __name__ == '__main__': file = sys.argv if not os.path.exists(file): print "Error: Unable to find file: " + file sys.exit(1) dbname = "yourdb" dbpass = "yourpassword" dbhost = "localhost" dbuser = "youruser" conn = mdb.connect(dbhost, dbuser, dbpass, dbname, charset="utf8") cursor = conn.cursor() f = feedparser.parse(file) l = len(f['entries']) print "Processing %d entries" % l for post in f['entries']: title = post.title link = post.link content = post.description content = content.encode('utf8') postdate = post.date slug = link.split("/")[-1] author = post.author post_author = "" if author == 'mel': post_author = "1" if author == 'sniffit': post_author = "2" if author == 'klks': post_author = "3" print "Importing post " + title q = "INSERT INTO wp_posts (post_date, post_date_gmt, post_content, post_title, post_name, post_author) VALUES (%s,%s,%s,%s,%s,%s)" cursor.execute(q, (postdate, postdate, content, title, slug, post_author)) conn.commit() cursor.close() conn.close()
There are a few things that this script doesn’t do, namely tags and categories. This can be coded, or done manually. Also, the RSS’ HTML output as generated by Plone may contain some garbage or wayward HTML tags (which are pretty consistent in around 80% of contents) and this can be cleaned up manually or by code.
Share this article
Graham Dumpleton is the developer of mod_wsgi
We happy to have Graham Dumpleton, developer of mod_wsgi to be here to meet-up with the local community. And hackerspaceKL is happy to host the meet-up.
Graham Dumpleton is the developer of mod_wsgi, an apache module implementation of Web Server Gateway Interface (wsgi), the standard of implementing web application for python.
This event is open to all members of the public.