0

Αφαιρέστε τα HTML tags από ένα string

Άλλαξα την πηγή των γιορτών για το twitter εορτολόγιο που έχω κάνει γιατί δεν μου φάνηκε πολύ πλήρης η λίστα που χρησιμοποίησα. Τώρα παίρνω την πληροφορία από ένα γνωστό website, διαβάζοντας την πρώτη σελίδα του, η οποία φυσικά είναι HTML.

Με αυτόν τον κώδικα μπορούμε πολύ εύκολα να κρατήσουμε μόνο τo κείμενο και να αφαιρέσουμε όλα τα HTML tags, που αρχίζουν με < και τελειώνουν με >, όπως και τα spaces &nbsp;.

 
def remove_html_tags(data):
    p = re.compile(r'<.*?>|&nbsp;')
    return p.sub('', data)
 

Ελαφρώς τροποποιημένος από τo site "Life is short - you need Python" ;)

0

GrubNG Python Client v0.3

I'm very happy to announce you the 0.3 version of the Python Client
This is a major release, so please update your clients.

Changelog 0.3

  • Fixed bug which produced wrong arcs. No more 401 errors. Closes bug: http://grub.org/?q=en/node/237 (thanks to Chris Hall, Bartek Jasicki and Balinny)
  • Handle compressed pages correctly
  • Return grub-error when we get only headers and no body
  • Better response type handling to deal with broken web servers
  • Works with the new upload server
  • Added config file support for username password
  • Close bug http://grub.org/?q=en/node/243
  • Added some sleep code to deal with dispatch server downtimes
  • Added some sleep code to deal with upload server errors
  • Username and password can be read from config file
  • Debug flag added
  • Info flag to help with debugging (thanks to Chris Hall)
  • Code cleanup

Direct Download

4

Εορτολόγιο στο Twitter + Identi.ca

Followup Post: Εορτολόγιο στο Twitter + Identi.ca - ο κώδικας

Πέρασα δυο ωρίτσες παίζοντας με το twitter. Δεν είμαι twitter addict και μόλις πρόσφατα απέκτησα το δικό μου twitter account αλλά έχω αρχίσει να μπαίνω στο πνεύμα. Δανείστηκα το xml αρχείο του εορτολογίου από την εφαρμογή 'Εορτολόγιο' του Grbytes και με python (πάλι!) το κόλλησα με το twitter. Θα ανεβάσω και τον κώδικα όταν τον σουλουπώσω λίγο. Προς το παρόν βάζω αυτό τον εύκολο τρόπο να twitt-άρεις χωρίς "ειδικές" βιβλιοθήκες από python και άλλες γλώσσες.

import urllib
 
def truncate(string,target):
    if len(string) > target:
        return string[:(target-3)] + "..."
    else:
        return string
 
def squawk(username,password,message):
"""Simple post-to-twitter function"""
    message = truncate(message,140) # trim message
    data = urllib.urlencode({"status" : message})
    res = urllib.urlopen( "https://%s:%s@twitter.com/statuses/update.xml" \
% (username, password), data)
 
e.g.: squawk('username', 'password', 'auto einai minima')

Η λύση αυτή δεν χρειάζεται το python twitter πακέτο, που παρόλο που είναι πολύ καλό και πιο κομψή λύση, δεν υπάρχει στους servers του dreamhost. Και μόνο με την urllib κάνεις μια χαρά updates :)

Grab it while it's hot!

http://www.identi.ca/eortologio

http://www.twitter.com/eortologio

1

Δρομολογείστε τα πάντα μέσω SSH

Ανακάλυψα μια σελίδα για το πως να δρομολογούμε τα πάντα "πάνω" από μία ssh σύνδεση και αγάπησα ακόμη περισσότερο αυτό το "προγραμματάκι". Το ότι είναι φοβερό το γνώριζα, αλλά το ότι δημιουργεί ένα πλήρως λειτουργικό SOCKS server με απλά ένα επιπλέον switch (-D) το κάνει απίστευτο!

 
~$ ssh -ND 3333 some.host.you.have.account.org
 

Με την χρήση της παραπάνω εντολής δημιουργείται ένας SOCKS server στον υπολογιστή μου, που ακούει στην πόρτα 3333, και δρομολογεί τα πάντα μέσα από το host "some.host.you.have.account.org". Η παράμετρος '-D <port>' είναι για τον SOCKS server και η '-N' δηλώνει ότι δεν θέλουμε να εκτελεστεί shell.

SOCKS server υποστηρίζουν διάφορα προγράμματα, όπως ο Firefox, αλλά και για όσα δεν υποστηρίζουν υπάρχουν λύσεις στην σελίδα που αναφέρομαι παραπάνω.

Δεν νομίζω καν ότι είναι νέο feature, αλλά εγώ τουλάχιστον είχα μείνει στο port forwarding :)

0

Grub Project Cafepress Shop

348845828v5_350x350_front_color-black

I though that I would be cool to wear a Grub Project t-shirt at the FOSDEM, so I created a Cafepress Grub Store for everyone to buy the needed merchandise :) Note that I get no money from selling this stuff, the prices are the starting prices Cafepress sets.

You can use the coupon code "BECALMCALMS" (without the quotes) to get your stuff with $5 discount! Sadly the offer only applies if that's your first Cafepress order, it's over $50 and only until 23 Jan 2009.

Enjoy the Grub Store!

BTW I'm always looking for good DIY services, like lulu for creating t-shirts to publishing your own (photo)book. Please let me now if you know of a great service, that respects it's users and the opensource community!

0

Grub Crawler – Python Client

grub-logoSince the last December I've been hacking on a python client for the (in)famous crawling project, Grub. The Grub project's goal is to crawl the whole web, in a decentralized way, and provides the data, for search engines to be build. Wikia Search is actually based on Grub's data. Only a C# client existed -which is actively developed now- so because I'm not a big fan of the whole .Net (or Mono, if you like it this way) idea I decided that should write a Python client.

You can grab the sources and start crawling yourself. Remember that you need a Wikia account first. The client is not in complete state but it works good enough for me to produce more than 3000 units of crawled pages, with 255 pages per unit, every day. Not bad, right?

Please give it a shot and let me know what you think and fill out some bug reports.

2

FOSDEM: 7-8 Φλεβάρη, Βρυξέλες

Δεν θα μπορούσα να χάσω την φοβερή προσφορά μιας βελγικής μπύρας και έτσι μετέφρασα το δελτίο τύπου της FOSDEM στα ελληνικά. Θα τα πούμε απο κοντά εκεί, θα είναι σίγουρα φοβερά!