#instalar python - twitter http://code.google.com/p/python-twitter/downloads/list
import twitter
import re
api = twitter.Api(username, password)
#1. actualizar el estado
api.PostUpdate('Tweet desde python ;)') #
#2. recuperar tus posts con links a otros uasuarios o los hashtags
statuses = api.GetUserTimeline()
posts=[]
for s in statuses:
tweet = s.text;
hash_regex = re.compile(r'#[0-9a-zA-Z+_]*',re.IGNORECASE)
user_regex = re.compile(r'@[0-9a-zA-Z+_]*',re.IGNORECASE)
savelog(hash_regex,'hashR')
savelog(smart_str(tweet),'tweet')
for tt in user_regex.finditer(tweet):
url_tweet = tt.group(0).replace('@','')
tweet = tweet.replace(tt.group(0),
'<a href="http://twitter.com/'+
url_tweet+'" title="'+
tt.group(0)+'">'+
tt.group(0)+'</a>')
for th in hash_regex.finditer(tweet):
url_hash = th.group(0).replace('#','%23')
if len ( th.group(0) ) > 2:
tweet = tweet.replace(th.group(0),
'<a href="http://search.twitter.com/search?q='+
url_hash+'" title="'+
th.group(0)+'">'+
th.group(0)+'</a>');
posts.append({'summary': tweet})
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2095"></script>
image = Image.open(imageField)
if image.mode != "RGB":
image = image.convert("RGB")
#big
image.save('image.jpg')
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2090"></script>
#1
from django.db import models
from django.contrib.auth.models import User, UserManager
class CustomUser(User):
birthday = models.DateField()
activation_key = models.CharField(max_length=255, blank=True, default='')
photo_url = models.CharField(max_length=50, blank=True) # cant incrementada de votaciones
User._meta.get_field('username')._unique = False
User._meta.get_field('email')._unique = True
User._meta.get_field_by_name('username')[0].max_length=75
#2 save child class
from users.models import CustomUser
def saveCustomUsers(request):
usr = CustomUser()
usr.username = 'macks'
usr.password = '123456'
usr.activation_key = 'sfsdf123456'
usr.birthday = datetime.now()
usr.photo_url = 'image.jpg'
usr.save()
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2083"></script>
#agregar templatetags a APPS de settings
1.-
apps/templatetags/userInfoTag.py
# -*- coding: utf-8 -*-
from django import template
from django.shortcuts import get_object_or_404
from django.contrib.auth.models import User
register = template.Library()
@register.inclusion_tag('admin/users/inclusionTags/userRecordsTags.html', takes_context=True)
def userRecords(context):
request = context['request']
user = get_object_or_404(User, id=request.user.id)
userName = user.first_name + ' ' + user.last_name
return {'userName': userName}
2.-
apps/templatetags/__init__.py
from django.template import add_to_builtins
add_to_builtins('templatetags.userInfoTag')
3.-
templates/admin/users/inclusionTags/userRecordsTags.html
{{ userName }} # return value of userInfotag.py
4.-
#se puede usar la plantilla userRecords.html en culaquiera otra plantilla
templates/admin/users/indexSuccess.html
<td>{% userRecords %}</td> #def userRecords
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2079"></script>
descragar y cambiar de nombre al archivo
def downloadImage(self):
img_url = 'http://img1cdn.adoosimg.com/b195d543e38e349deac032b41be043c7-1-5.jpg'
imgName = 'b195d543e38e349deac032b41be043c7-1-5.jpg'
imgN = "peque_%s"%imgName.replace('5.','7.') if imgName[-5:]=='5.jpg' else imgName
file_path = "%s/adoos/%s" % (settings.UPLOAD_PATH, imgN)
downloaded_image = file(file_path, "wb")
image_on_web = urllib.urlopen(img_url)
while True:
buf = image_on_web.read(65536)
if len(buf) == 0:
break
downloaded_image.write(buf)
downloaded_image.close()
image_on_web.close()
return file_path
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2073"></script>
def __validateVideoName(videoname):
import string
rs = False
if videoname:
whiteSpace = False if re.search(' ',videoname) else True
specialChar = True if re.compile('[a-zA-Z0-9._-]+$').match(videoname) else False
if whiteSpace and specialChar:
rs = True
return rs
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2069"></script>
dsc = ['uno','dos','tres']
line = """#%d# rn
%s rnrn""" % (i+1, dsc)
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2067"></script>
def remove_html_tags(data):
p = re.compile(r'<[^<]*?/?>')
return p.sub('', data)
Here is another function to remove more than one consecutive white spaces:
def remove_extra_spaces(data):
p = re.compile(r's+')
return p.sub(' ', data)
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2066"></script>
tips
string = '[1,2,3]'
list = eval(string)
print list
[1, 2, 3]
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2063"></script>
usando la libreria ffmpeg
import commands
import os
def execute():
cmd = 'c:/ffmpeg/ffmpeg.exe -y -itsoffset -4 -i c:/input.mpg -vframes 1 -s 100x90 -f image2 c:/uploads/img_gen.jpg'
#c = commands.getoutput(cmd) # linux
c = os.system(self.cmd) #windows
return c
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2058"></script>