Форум сайта python.su
from oauthtwitter import *
import sys
import os
twitter = None
consumerKey = "9JYro3GTfqLsqFxpI5ljmg"
consumerSecret = "1dDfoviitbiLx9XsZrdkATynbrpLkzT25RJN3t3yDDM"
def auth():
authToken = None
authSecret = None
if os.path.exists('/tmp/twitter.tmp'):
f = open('/tmp/twitter.tmp', 'r')
authToken = f.readline().strip()
authSecret = f.readline().strip()
print "oauth_token: " + authToken
print "oauth_token_secret: " + authSecret
f.close()
needAuth = True
if authToken!=None and authSecret!=None:
twitter = OAuthApi(consumerKey, consumerSecret, authToken, authSecret)
if twitter.autorized():
needAuth = False
if needAuth:
twitter = OAuthApi(consumerKey, consumerSecret)
temp_credentials = twitter.getRequestToken()
print temp_credentials
print twitter.getAuthorizationURL(temp_credentials)
oauth_verifier = raw_input('What is the PIN? ')
access_token = twitter.getAccessToken(temp_credentials, oauth_verifier)
print access_token
print("oauth_token: " + access_token['oauth_token'])
print("oauth_token_secret: " + access_token['oauth_token_secret'])
f = open('/tmp/twitter.tmp', 'w')
f.write('%s\n%s'%(access_token['oauth_token'], access_token['oauth_token_secret']))
f.close()
twitter = OAuthApi(consumerKey, consumerSecret, access_token['oauth_token'], access_token['oauth_token_secret'])
return twitter
twitter = auth()
update = twitter.UpdateStatus("Hello World!")
if update:
print "YAHOOOO"
else:
print "FUUUUU"
import Tkinter, Image
from PIL import ImageTk
FILENAME = "001.jpg"
tk = Tkinter.Tk()
c = Tkinter.Canvas(tk, width=500, height=500)
#c.pack(expand = YES, fill = BOTH)
src_img = Image.open(FILENAME)
img = ImageTk.PhotoImage(src_img)
c.create_image(0, 0, image=img, anchor="nw")
def callback(event):
что здесь должно быть?
print repr(undermouse)
c.bind("<Button-1>", callback)
c.pack()
Tkinter.Label(tk, text=FILENAME).pack()
tk.mainloop()
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.
IPython 0.10.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: %pwd
Out[1]: 'C:\\Documents and Settings\\\xcc\xe8\xf5\xe0\xe8\xeb'
In [2]: !echo Здравствуй, мир!
‡¤а ўбвўг©, ¬Ёа!
class OrderTbl(models.Model):
idOrder = models.AutoField(primary_key=True, db_column='idOrder') # Field name made lowercase.
numorder = models.CharField(max_length=45, db_column='numOrder') # Field name made lowercase.
nameorder = models.CharField(max_length=765, db_column='nameOrder') # Field name made lowercase.
class Meta:
db_table = u'Order_tbl'
def __unicode__(self):
return '%s %s %s' % (self.idOrder, self.numorder, self.nameorder, )
class BeginigTbl(models.Model):
idbeginig = models.AutoField(primary_key=True, db_column='idBeginig')
percentbegining = models.IntegerField(null=True, db_column='percentBegining', blank=True)
order_tbl_idorder = models.ForeignKey(OrderTbl, db_column='Order_tbl_idOrder')
class Meta:
db_table = u'Beginig_tbl'
def __unicode__(self):
return '%s' % (self.percentbegining)
def MPlan_view(request):
order = OrderTbl.objects.all().order_by('idOrder')
begin = BeginigTbl.objects.all()
matches = list(chain(order,begin))
return render_to_response('MPlan_view.html',{'matches': matches})
<html>
<body>
<table border="2">
{% for i in matches %}
<tr>
<td>{{ i.idOrder }}</td>
<td>{{ i.numorder }}</td>
<td>{{ i.nameorder }}</td>
<td>{{ i.percentbegining }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>
CREATE OR REPLACE FUNCTION translit_py(seq varchar(64), typ integer)
RETURNS varchar(64) AS
$BODY$
ENCODING_MAP = {
u'а':u'a', u'б':u'b', u'в':u'v', u'г':u'g', u'д':u'd', u'е':u'e', u'ё':u'yo', u'ж':u'zh',
u'з':u'z', u'и':u'i', u'й':u'j', u'к':u'k', u'л':u'l', u'м':u'm', u'н':u'n', u'о':u'o',
u'п':u'p', u'р':u'r', u'с':u's', u'т':u't', u'у':u'u', u'ф':u'f', u'х':u'h', u'ц':u'c',
u'ч':u'ch', u'ш':u'sh', u'щ':u'sh', u'ъ':u'', u'ы':u'y', u'ь':u'', u'э':u'e', u'ю':u'yu',
u'я':u'ya',
u'А':u'A', u'Б':'B', u'В':'V', u'Г':'G', u'Д':'D', u'Е':'E', u'Ё':'Yo', u'Ж':'Zh',
u'З':u'Z', u'И':'I', u'Й':'J', u'К':'K', u'Л':'L', u'М':'M', u'Н':'N', u'О':'O',
u'П':u'P', u'Р':'R', u'С':'S', u'Т':'T', u'У':'U', u'Ф':'F', u'Х':'H', u'Ц':'C',
u'Ч':u'Ch', u'Ш':'Sh', u'Щ':'Sh', u'Ъ':'', u'Ы':'Y', u'Ь':'', u'Э':'E', u'Ю':'Yu',
u'Я':u'Ya',
u'Є':u'Ye', u'І':'I', u'Ї':'Yi', u'Ґ':'G', u'є':'ye', u'і':'i', u'ї':'yi', u'ґ':'g',
}
KEYBOARD_MAP = {
u'й':u'q', u'ц':u'w', u'у':u'e', u'к':u'r', u'е':u't', u'н':u'y', u'г':u'u', u'ш':u'i', u'щ':u'o', u'з':u'p', u'х':u'[', u'ъ':u']',
u'ф':u'a', u'ы':u's', u'в':u'd', u'а':u'f', u'п':u'g', u'р':u'h', u'о':u'j', u'л':u'k', u'д':u'l', u'ж':u'', u'э':u"'",
u'я':u'z', u'ч':u'x', u'с':u'c', u'м':u'v', u'и':u'b', u'т':u'n', u'ь':u'm', u'б':u',', u'ю':u'.',
u'Й':u'Q', u'Ц':u'W', u'У':u'E', u'К':u'R', u'Е':u'T', u'Н':u'Y', u'Г':u'U', u'Ш':u'I', u'Щ':u'O', u'З':u'P', u'Х':u'[', u'Ъ':u']',
u'Ф':u'A', u'Ы':u'S', u'В':u'D', u'А':u'F', u'П':u'G', u'Р':u'H', u'О':u'J', u'Л':u'K', u'Д':u'L', u'Ж':u'', u'Э':u"'",
u'Я':u'Z', u'Ч':u'X', u'С':u'C', u'М':u'V', u'И':u'B', u'Т':u'N', u'Ь':u'M', u'Б':u',', u'Ю':u'.',
u'Є':u'"', u'І':u'S', u'Ї':u'}', u'Ґ':u'|', u'є':u"'", u'і':u's', u'ї':u']', u'ґ':u'\\',
}
result=''
for k in seq:
if typ == 1:
result += ENCODING_MAP.get(k, k)
elif typ == 2:
result += KEYBOARD_MAP.get(k, k)
return result
$BODY$
LANGUAGE plpythonu VOLATILE STRICT
COST 100;
ALTER FUNCTION translit_py(character varying, integer) OWNER TO postgres;
SELECT translit_py('проверка', 1)
cgidata = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
File "/usr/lib/python2.6/cgi.py", line 508, in __init__
self.read_multi(environ, keep_blank_values, strict_parsing)
File "/usr/lib/python2.6/cgi.py", line 632, in read_multi
environ, keep_blank_values, strict_parsing)
File "/usr/lib/python2.6/cgi.py", line 510, in __init__
self.read_single()
File "/usr/lib/python2.6/cgi.py", line 647, in read_single
self.read_lines()
File "/usr/lib/python2.6/cgi.py", line 669, in read_lines
self.read_lines_to_outerboundary()
File "/usr/lib/python2.6/cgi.py", line 697, in read_lines_to_outerboundary
line = self.fp.readline(1<<16)
IOError: request data read error