Saturday, 20 January 2018

Create a blog post from Twitter results

Following on from my post yesterday and setting up a means to post to blogger using python I have combined the following elements in this post: 

  • Posting to blogger
  • Scraping Twitter
  • Connecting to Database
  • Getting data from database
  • pandas styles 
  • pandas to html 
There is of course scope to add more to this, I can scrape more websites and I can certainly improve on the formatting of the tables. I can do more analytics by looking into the words within the tweets and add some graphs. So lots more to be done. I can also use something like schedule to get this to run automatically and much more. 

Pretty much everything needed for this post is contained in the code below or in the preceding posts. 

The end result is something like this

The code: 


Friday, 19 January 2018

Automating blogger with python

So I have been thinking about what I could automate that I do and I was thinking of creating a blog that was entirely automated, basically to prove that I could. Of course in order to automate the content I need to have something that is constantly updating as my subject matter, therefore I am going to use Twitter as my data source. The reason for this is that I already have some code that can use to my starting point for collecting the data. 

At this point the subject is not important but I will probably go with Low-Carb as I have an old blog that I started for this but never really got into. So the next step is posting to blogger. After that I need to look into completely automating the running of the script. This post however if how to post to blogger from python, again I have an amazing post on stack-overflow to thank for the code and full credit to them and the post on stack-overflow. 

output from running the script below

I will add that you do need to go to the Google Console and set up the blogger v3 api to allow permission to post this and then connect to the json file in the script. Note that there are additional bits in this code that will be removed when actually creating the end product. 


The code:




Thursday, 18 January 2018

Distributing it, part 2

Having done part one I am now going part 2. We we now have code that accepts SQL, I would probably do this as a report i.e.pick the report rather than typing SQL. This post will be very short as basically the pyinstaller library does all the work for you.

1) Set up the python code where you want it.
2) Make sure you have installed the pyinstaller library 
3) Run the command line (see above link) to create the exe.
4) Job done.

The potential for this is huge and there are obvious applications, especially where you have built a front-end in tkinter. You build your own front-end tool for a database and allow your users to run reports, you can automate web processes by linking with Selenium and much more.

Below is a gif of one of the exe's I have made in action, in this instance it is running the very simple piece of code shown below:

The code:

The Exe: