Seguro que te interesa (GitHub behind the scenes – parte 1)

Esta entrada es un poco atípica, realmente no es más que una excusa para presentaros el nuevo repositorio en GitHub de esta web.

Poco a poco quiero ir ofreciendo los scripts que me hacen la vida más sencilla y que pueden ayudaros en ciertas tareas. Para estrenar el repo, he pensado en contar cómo hago la entrada de los Viernes en las que os listo las noticias que me han parecido más interesantes de la semana.

Tras unas cuantas entradas en las que iba recopilando enlaces a mano, decidí que así no podía continuar. Como dice un gran amigo, soy muy vago, pero vago de los buenos. Eso me hace pensar en cómo automatizar absolutamente todo lo que hago para que las tareas repetitivas las haga una CPU y yo pueda centrarme en ideas felices o a imaginar qué isla me compraré cuando me toque la lotería.

Gracias a lo de internet, tiro de Twitter para estar al tanto de las noticias de última hora y suelo hacer retweet de lo que me llama la atención. Noticias, herramientas, análisis, humor… pero todo relacionado con lo que me apasiona, la seguridad de la información.

Como últimamente le he cogido cariño a Python (al pitón como le llamo alegremente por la oficina de Dive), decidí tirar de un poco de crawling vía BeautifulSoup para buscar en twitter ciertos elementos.

Básicamente lo que hago es abrir la página de Twitter de SecurityInside y busco todos los retweets. De cada uno, me quedo con los elementos interesantes (título, autor, imágen y texto) y los pongo en forma de tabla para que se vea de forma decente como una entrada del blog. Básicamente esto:

# Get retweet info
# ---------------------------------------------------------------------------------------
req = requests.get(url)
statusCode = req.status_code

if statusCode == 200:

    html = BeautifulSoup(req.text, "html.parser")

    for timeline in html.find_all('div', {'data-test-selector':'ProfileTimeline'}):
        for oltag in timeline.find_all('ol', {'id':'stream-items-id'}):
            for litag in oltag.find_all('li'):
                for div in litag.find_all('div', {"class" : "tweet"}):
                    try:
                        if div['data-retweet-id']:

                            for small in litag.find_all('small', {"class" : "time"}):
                                for a in small.find_all('a', {"class" : "tweet-timestamp"}):
                                    try:
                                        date = a['title'].encode("ascii", "ignore")

                                    except Exception as e:
                                        None

                            title = div.find('p', {'class':'TweetTextSize'}).getText().split('http')[0].encode("ascii", "ignore")

                            link = div.find('a', {'class':'twitter-timeline-link'}).getText().encode("ascii", "ignore")

                            name = div.find('span', {'class':'username'}).getText().split('@')[1].encode("ascii", "ignore")
							
                            for img in div.find_all('img'):
                                if 'avatar' in img:
                                    image = 'http://securityinside.info/wp-content/uploads/logo.png'
                                else:
                                    image = img['src'].encode("ascii", "ignore")

                            print '<tr><td style="vertical-align:middle;border:0px;margin: 0px 0px"><img class="aligncenter" src="' + image + '" alt="' + name + '" width="150"/></td>\n<td style="vertical-align:middle;border:0px;margin: 0px 0px"><strong><a href="https://twitter.com/' + name + '" target="_blank">' + date + ' @' + name + ':<br></a></strong> <a href="' + link + '" target="_blank">' + title + '</a></td></tr>'

                    except Exception as e:
                        None

else:
    print "Status Code %d" %statusCode

El ejemplo es sólo parte del script completo. Si quieres utilizarlo o modificarlo, puedes descargarlo desde nuestro repositorio en GitHub.

 

Como podéis ver, sólo tengo que copiar la línea que me genera el script e insertarla en la entrada. La tarea se completa añadiendo el texto habitual y configurando las categorías, la imágen y los valores SEO.

Vale, me vais a decir que eso también se puede automatizar. La respuesta es que si, por eso os dejo pendiente la segunda parte del artículo en la que dedicaré otro rato a generar la entrada completa (insertando en base de datos y demás).

Pero poco a poco, que estoy un poco liado gestionando los backups anti malware de la junta directiva… pero eso es otra historia que os voy a contar en breve.

¿Os lo vais a perder?

Cristóbal Espinosa
682 comentarios
  1. najlepsze escape roomy
    najlepsze escape roomy Dice:

    Hello there, just became alert to your blog through Google, and found that
    it is really informative. I’m gonna watch out for brussels.
    I will appreciate if you continue this in future.
    Numerous people will be benefited from your writing.
    Cheers! Escape room

  2. can't sell my house
    can't sell my house Dice:

    After going over a number of the articles on your site, I honestly appreciate your way of blogging. I bookmarked it to my bookmark webpage list and will be checking back soon. Take a look at my web site too and let me know your opinion.

  3. vents
    vents Dice:

    Hello there! This blog post couldn’t be written any better! Looking through this article reminds me of my previous roommate! He always kept talking about this. I’ll send this information to him. Fairly certain he will have a very good read. I appreciate you for sharing!

  4. Latest Songs
    Latest Songs Dice:

    I’m impressed, I must say. Seldom do I encounter a blog that’s both equally educative and amusing, and without a doubt, you’ve hit the nail on the head. The issue is an issue that too few men and women are speaking intelligently about. I’m very happy that I stumbled across this during my hunt for something concerning this.

  5. Deus Medical
    Deus Medical Dice:

    An intriguing discussion is definitely worth comment. There’s no doubt that that you need to write more about this topic, it might not be a taboo matter but generally people don’t discuss these topics. To the next! All the best!

  6. ricepurityscore.kktix.cc
    ricepurityscore.kktix.cc Dice:

    Aw, this was an incredibly nice post. Taking a few minutes and actual effort to generate a top notch article… but what can I say… I procrastinate a whole lot and don’t seem to get nearly anything done.

  7. OEM running jackets
    OEM running jackets Dice:

    You are so cool! I do not think I’ve read through something like this before. So nice to discover another person with a few genuine thoughts on this topic. Really.. many thanks for starting this up. This web site is one thing that is required on the web, someone with a bit of originality.

  8. ngentot memek
    ngentot memek Dice:

    Spot on with this write-up, I seriously believe this amazing site needs a lot more attention. I’ll probably be returning to read more, thanks for the advice!

  9. naked
    naked Dice:

    I blog frequently and I genuinely appreciate your information. This great article has truly peaked my interest. I am going to bookmark your site and keep checking for new information about once a week. I subscribed to your RSS feed too.

  10. iptv
    iptv Dice:

    You are so awesome! I do not think I’ve read through a single thing like that before. So nice to discover someone with original thoughts on this subject matter. Seriously.. thanks for starting this up. This site is something that is required on the internet, someone with some originality.

  11. iptv
    iptv Dice:

    Hello! I could have sworn I’ve been to this website before but after looking at some of the posts I realized it’s new to me. Anyways, I’m certainly delighted I stumbled upon it and I’ll be book-marking it and checking back often.

  12. iptv
    iptv Dice:

    Hello! I could have sworn I’ve visited this blog before but after looking at some of the articles I realized it’s new to me. Nonetheless, I’m definitely happy I stumbled upon it and I’ll be bookmarking it and checking back often.

  13. iptv
    iptv Dice:

    I was very happy to discover this great site. I want to to thank you for ones time just for this wonderful read!! I definitely appreciated every part of it and I have you saved to fav to see new stuff on your web site.

  14. 33win
    33win Dice:

    It’s hard to come by experienced people about this topic, however, you sound like you know what you’re talking about! Thanks

  15. shakibalhasan
    shakibalhasan Dice:

    Nice post. I learn something totally new and challenging on blogs I stumbleupon on a daily basis. It will always be useful to read through articles from other authors and use a little something from their web sites.

  16. rikviptours
    rikviptours Dice:

    Next time I read a blog, Hopefully it won’t fail me as much as this particular one. After all, I know it was my choice to read, nonetheless I truly believed you would probably have something useful to talk about. All I hear is a bunch of complaining about something you could fix if you were not too busy looking for attention.

  17. mibet
    mibet Dice:

    Hi, I do believe this is a great web site. I stumbledupon it 😉 I may come back yet again since I book marked it. Money and freedom is the greatest way to change, may you be rich and continue to guide others.

  18. nhacai123dzo
    nhacai123dzo Dice:

    Spot on with this write-up, I honestly think this amazing site needs much more attention. I’ll probably be back again to read more, thanks for the info.

  19. iptv
    iptv Dice:

    Good post. I learn something new and challenging on websites I stumbleupon every day. It’s always interesting to read content from other authors and use something from other websites.

  20. top88bet
    top88bet Dice:

    Greetings! Very useful advice in this particular article! It is the little changes which will make the greatest changes. Many thanks for sharing!

  21. Long Island NY
    Long Island NY Dice:

    When I initially commented I appear to have clicked the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I get four emails with the exact same comment. Perhaps there is a way you are able to remove me from that service? Kudos.

  22. Whitescreen59
    Whitescreen59 Dice:

    A motivating discussion is worth comment. I think that you should publish more about this issue, it might not be a taboo matter but typically people do not discuss such subjects. To the next! Cheers!

  23. live adult webcams
    live adult webcams Dice:

    I’m impressed, I must say. Rarely do I encounter a blog that’s both equally educative and engaging, and let me tell you, you have hit the nail on the head. The issue is something that too few folks are speaking intelligently about. I am very happy that I found this during my search for something regarding this.

  24. good88
    good88 Dice:

    Great blog you’ve got here.. It’s hard to find good quality writing like yours these days. I really appreciate individuals like you! Take care!!

  25. Backpage Alternative Washington DC
    Backpage Alternative Washington DC Dice:

    I’m impressed, I have to admit. Rarely do I come across a blog that’s equally educative and engaging, and let me tell you, you have hit the nail on the head. The problem is something which not enough folks are speaking intelligently about. Now i’m very happy that I came across this during my hunt for something concerning this.

  26. Destination
    Destination Dice:

    Spot on with this write-up, I actually believe this site needs much more attention. I’ll probably be returning to see more, thanks for the information.

  27. bobres-iptv
    bobres-iptv Dice:

    Spot on with this write-up, I absolutely believe this amazing site needs a great deal more attention. I’ll probably be returning to see more, thanks for the info!

  28. Escorts Near Me
    Escorts Near Me Dice:

    Right here is the right web site for everyone who wants to find out about this topic. You know so much its almost hard to argue with you (not that I personally will need to…HaHa). You certainly put a fresh spin on a topic that’s been written about for decades. Wonderful stuff, just excellent.

  29. Efficient and Trustworthy PDF Solutions
    Efficient and Trustworthy PDF Solutions Dice:

    You are so awesome! I don’t think I’ve read through something like that before. So wonderful to find another person with some genuine thoughts on this subject matter. Really.. thank you for starting this up. This site is one thing that is required on the web, someone with a bit of originality.

  30. question permis
    question permis Dice:

    Hello there! I could have sworn I’ve been to this web site before but after looking at many of the posts I realized it’s new to me. Anyways, I’m definitely pleased I discovered it and I’ll be bookmarking it and checking back often!

  31. pabriktoto
    pabriktoto Dice:

    May I simply say what a comfort to discover someone that genuinely knows what they are discussing on the internet. You actually realize how to bring an issue to light and make it important. More people must look at this and understand this side of your story. It’s surprising you aren’t more popular given that you surely possess the gift.

  32. Bransoletki Granat
    Bransoletki Granat Dice:

    Hi! I could have sworn I’ve visited this website before but after looking at a few of the posts I realized it’s new to me. Anyhow, I’m certainly pleased I found it and I’ll be bookmarking it and checking back often.

  33. Ремонт фотовспышек
    Ремонт фотовспышек Dice:

    Профессиональный сервисный центр по ремонту фототехники в Москве.
    Мы предлагаем: ремонт фотовспышек на дому
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
    Подробнее на сайте сервисного центра remont-vspyshek-realm.ru

  34. Ремонт проекторов
    Ремонт проекторов Dice:

    Профессиональный сервисный центр по ремонту фото техники от зеркальных до цифровых фотоаппаратов.
    Мы предлагаем: мастер по ремонту проекторов
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  35. linetogel
    linetogel Dice:

    Aw, this was an incredibly nice post. Taking the time and actual effort to generate a good article… but what can I say… I hesitate a whole lot and don’t seem to get nearly anything done.

  36. Раковины в Москве
    Раковины в Москве Dice:

    Хочу поделиться опытом покупки в одном интернет-магазине сантехники. Решил обновить ванную комнату и искал место, где можно найти широкий выбор раковин и ванн. Этот магазин приятно удивил своим ассортиментом и сервисом. Там есть всё: от классических чугунных ванн до современных акриловых моделей.

    Если вам нужна купить умывальник в ванную , то это точно туда. Цены конкурентные, а качество товаров подтверждено сертификатами. Консультанты помогли с выбором, ответили на все вопросы. Доставка пришла вовремя, и установка прошла без проблем. Остался очень доволен покупкой и сервисом.

  37. Ремонт блоков питания в Москве
    Ремонт блоков питания в Москве Dice:

    Профессиональный сервисный центр по ремонту компьютерных блоков питания в Москве.
    Мы предлагаем: ремонт блока питания цена
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  38. ремонт сотовых телефонов
    ремонт сотовых телефонов Dice:

    Мой телефон перестал заряжаться, и я не знал, что делать. По совету друга обратился в этот сервисный центр. Мастера быстро нашли проблему и устранили её. Теперь мой телефон снова в строю! Рекомендую всем: сколько стоит выровнять телефон.

  39. ремонт кондиционеров
    ремонт кондиционеров Dice:

    <a href=»https://remont-kondicionerov-wik.ru»>сколько стоит ремонт кондиционера</a>

  40. Ремонт персональных компьютеров в Москве
    Ремонт персональных компьютеров в Москве Dice:

    Профессиональный сервисный центр по ремонту компьютероной техники в Москве.
    Мы предлагаем: ремонт системного блока компьютера
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  41. Ремонт камеры наблюдения в Москве
    Ремонт камеры наблюдения в Москве Dice:

    Профессиональный сервисный центр по ремонту камер видео наблюдения по Москве.
    Мы предлагаем: сервисные центры ремонту камер в москве
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  42. сервис центры в нижнем новгороде
    сервис центры в нижнем новгороде Dice:

    Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
    Мы предлагаем: сервис центры бытовой техники нижний новгород
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  43. ซีรี่ย์จีน123
    ซีรี่ย์จีน123 Dice:

    Hello, I do believe your blog may be having web browser compatibility issues. Whenever I look at your website in Safari, it looks fine but when opening in IE, it’s got some overlapping issues. I merely wanted to provide you with a quick heads up! Aside from that, excellent blog!

  44. Часовые мастерские в Москве
    Часовые мастерские в Москве Dice:

    Профессиональный сервисный центр по ремонту кнаручных часов от советских до швейцарских в Москве.
    Мы предлагаем: ремонт часов цена
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  45. ремонт бытовой техники в перми
    ремонт бытовой техники в перми Dice:

    Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
    Мы предлагаем: ремонт бытовой техники в перми
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

Los comentarios están desactivados.