Archive for July, 2016


July 17, 2016 Leave a comment

Using Flask-RESTful, I needed an API endpoint that accepts JSON data.

I found the solution here: You can copy / paste that code. Note that the JSON data is POSTed to your API endpoint, thus you need to implement the post() method.

However, how to test it?

1) using cURL:

$ curl -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d "{\"Hello\":\"Karl\"}" http://domain/your_api_endpoint

Damn, that’s compicated, right? Is there an easier way?

2) using httpie:
You can install httpie with your favorite package manager. Then:

$ http POST http://domain/your_api_endpoint Hello=Karl

get the tweets of a user and save them in CSV

July 16, 2016 Leave a comment
Categories: python Tags: , , ,

remove tags from HTML

July 13, 2016 Leave a comment

You have an HTML string and you want to remove all the tags from it.

Install the package “bleach” via pip. Then:

>>> import bleach
>>> html = "Her <h1>name</h1> was <i>Jane</i>."
>>> cleaned = bleach.clean(html, tags=[], attributes={}, styles=[], strip=True)
>>> html
'Her <h1>name</h1> was <i>Jane</i>.'
>>> cleaned
'Her name was Jane.'

Tip from here.

Categories: python Tags: , ,