Vizible’s Blog

cython cause install skype4py failed

Posted in Python by wearetherock on September 18, 2009
$ sudo python setup.py install
running install
running build
running build_py
running build_ext
cythoning Skype4Py/utils.py to Skype4Py/utils.c

Error converting Pyrex file to C:
------------------------------------------------------------
...
        self._EventHandlerObj = Obj

    @staticmethod
    def __AddEvents_make_event(Event):
        # TODO: rework to make compatible with cython
        return property(lambda self: self._GetDefaultEventHandler(Event),
                       ^
------------------------------------------------------------

/dos/library/Skype4Py/tar/Skype4Py-1.0.31.0/Skype4Py/utils.py:462:24: Expected an identifier or literal
building 'Skype4Py.utils' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I. -I/usr/include/python2.6 -c Skype4Py/utils.c -o build/temp.linux-i686-2.6/Skype4Py/utils.o -O3
gcc: Skype4Py/utils.c: No such file or directory
gcc: no input files
error: command 'gcc' failed with exit status 1
$

~
Then

$ sudo apt-get remove cython
$ sudo python setup.py install
running install
running build
running build_py
copying Skype4Py/API/windows.py -> build/lib.linux-i686-2.6/Skype4Py/API
copying Skype4Py/API/faked_dbus.py -> build/lib.linux-i686-2.6/Skype4Py/API
copying Skype4Py/API/darwin.py -> build/lib.linux-i686-2.6/Skype4Py/API
running install_lib
...
byte-compiling /usr/local/lib/python2.6/dist-packages/Skype4Py/Languages/bg.py to bg.pyc
byte-compiling /usr/local/lib/python2.6/dist-packages/Skype4Py/Languages/lt.py to lt.pyc
byte-compiling /usr/local/lib/python2.6/dist-packages/Skype4Py/Languages/sv.py to sv.pyc
byte-compiling /usr/local/lib/python2.6/dist-packages/Skype4Py/Languages/ro.py to ro.pyc
byte-compiling /usr/local/lib/python2.6/dist-packages/Skype4Py/conversion.py to conversion.pyc
running install_egg_info
Writing /usr/local/lib/python2.6/dist-packages/Skype4Py-1.0.31.0.egg-info
$

~

Advertisements
Tagged with: , ,

C – Create share library

Posted in Programming by wearetherock on August 21, 2009

1. Code
==================================

// test.c
#include 
static char *name;
void printName(){
	printf("name = %s\n", name);
}
void setName(char *n){
	name = n;
}

~
2. Compile
==================================

> gcc -c test.c -o test.o
> gcc -shared -o libfoo.so test.o

~
3. Test
==================================

>>> from ctypes import cdll
>>> lib = cdll.LoadLibrary('libfoo.so')
>>> lib.setName('java')
27090740
>>> lib.printName()
name = java
12
>>>
Tagged with: , , ,

GoAhead! – I don’t known

Posted in Logs, Python by wearetherock on July 23, 2009

When I run python script there are username and password prompt

~

Enter username for GoAhead at localhost:8080:
Enter password for in GoAhead at localhost:8080:

~
What’s this? , i didn’t implement this thing.

Tagged with: , ,

Python – How to use Flickr API?

Posted in Python by wearetherock on July 11, 2009
# use http://stuvel.eu/flickrapi
# API key get from flickr web site

import flickrapi
class Uploader :
	def __init__(self, apiKey, secretKey) :
		self.flickr = flickrapi.FlickrAPI(apiKey, secretKey)
		(token, frob) = self.flickr.get_token_part_one(perms='write')
		if not token: raw_input("Press ENTER after you authorized this program")
		self.flickr.get_token_part_two((token, frob))

	def showProgress(self, progress, done) :
		if done :
			print 'Done uploading'
		else :
			print 'At %s%%' % progress

	def upload(self, image):
		self.flickr.upload(filename = image, callback = self.showProgress)

if __name__ == '__main__' :
	apiKey = 'xxxx'
	secretKey = 'xxxx'
	uploader = Uploader(apiKey, secretKey)
	image = 'into_the_wild.png'
	uploader.upload(image)
Tagged with: ,

Python – Broadcast UDP II

Posted in Python by wearetherock on February 2, 2009

ทำต่อจากของเดิม Python – Broadcast UDP เมื่อ Tomboy บันทึกข้อมูล(เป็นช่วง ๆ) มันจะส่ง Signal ออกมา  ซึ่งเราจะส่งข้อมูลออกไปช่วงนั้นแต่ต้องตรวจสอบก่อนว่าผู้ใช้เขียนโน็ตเสร็จหรือยัง  โดยดูจาก ### ถ้ามี ### ตอนท้ายแสดงว่าเสร็จแล้ว โปรแกรมจะ Broadcast ข้อความนั้นออกไปทันที จบ

แต่พิมพ์ภาษาไทยไม่ได้ มัน error ตอน encode จะแก้ยังไง?

import dbus, gobject, socket
from dbus.mainloop.glib import DBusGMainLoop

class MyNote :
	def __init__(self):
		self.bus = dbus.SessionBus()
		self.object = self.bus.get_object("org.gnome.Tomboy", "/org/gnome/Tomboy/RemoteControl")
		self.tomboy = dbus.Interface(self.object, "org.gnome.Tomboy.RemoteControl")
		self.bus.add_signal_receiver(self.save_event_handler, "NoteSaved")
	def save_event_handler(self, note_uri):
		message = self.tomboy.GetNoteContents(note_uri)

		if message.endswith("###") :
			message.encode('utf-8')  # why not support thai, alway error when meet thai char..
			self.send_to_other(str(message))
	
	def send_to_other(self, message):

		my_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
		my_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
		my_socket.sendto(message, ('<broadcast>',8881))

		print 'sent (%s) complete ..' % (message)

def main():
	DBusGMainLoop(set_as_default = True)
	note = MyNote()
	loop = gobject.MainLoop()

	print 'start ...'
	loop.run()

if __name__ == "__main__" :
	main()
Tagged with: , , , ,