Skip to content

Commit

Permalink
new posts
Browse files Browse the repository at this point in the history
  • Loading branch information
mdyzma committed Dec 19, 2017
2 parents 86935dd + 7b8ed81 commit 1ae87bb
Show file tree
Hide file tree
Showing 11 changed files with 1,551 additions and 43 deletions.
76 changes: 66 additions & 10 deletions _drafts/2017-07-12-social-media-analysis-part-ii.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ Flask application presenting social media accounts analysis in form of dashboard

## Series consists of:

* [Social media analysis with Flask, Part I]({{site.url}}/2017/06/07/social-media-analysis-part-I/) (Setting environment, flask, Travis CI/Heroku CD )
* [Social media analysis with Flask, Part II]({{site.url}}/2017/07/12/social-media-analysis-part-ii/) (Templates, login/register mechanism, data storage)
<!-- * [Social media analysis with Flask, Part III]({{site.url}}/2017/08/17/social-media-analysis-part-iii) (Twitter data analysis) -->
* [Social media analysis with Flask, Part I]({{site.url}}{% post_url 2017-06-07-social-media-analysis-part-I %}) (Setting environment, flask, Travis CI/Heroku CD )
* [Social media analysis with Flask, Part II]({{site.url}}{% post_url 2017-07-12-social-media-analysis-part-ii %}) (Templates, login/register mechanism, data storage)


<!--
* [Social media analysis with Flask, Part IV]({{site.url}}/2017/09/09/social-media-analysis-part-iv/) (Twitter data analysis)
* [Social media analysis with Flask, Part V]({{site.url}}/2017/10/18/social-media-analysis-part-v/) (Facebook data analysis)
* [Social media analysis with Flask, Part VI]({{site.url}}/2017/11/05/social-media-analysis-part-vi/) (GitHub data analysis)
-->
## Part II


Expand Down Expand Up @@ -480,7 +475,25 @@ def register_blueprints(app):

{% endhighlight %}

This file will initialize flask app, register all extensions and blueprints to the current context.
This file will initialize flask app, register all extensions and blueprints to the current context. We can print all endpoints using `manage.py show-urls` command:

{% highlight bash %}
(md_analytics) [mdyzma@devbox md_analytics]$ python manage.py show-urls

--------------------------------------------------------------------------------
DEBUG in app [/home/mdyzma/md_analytics/app/app.py:27]:
Debug toolbar initialized
--------------------------------------------------------------------------------
Rule Endpoint
---------------------------------------------------------------------------
/ public.home
/login public.login
/logout public.logout
/register public.register
/static/<path:filename> static
/static/<path:filename> public.

{% endhighlight %}


### Template
Expand Down Expand Up @@ -750,7 +763,7 @@ __/templates/login.html__
<section class="view">
<div class="container" style="padding-top: 75px">
<h1>Login</h1>
<form>
<form method="post">
<span>Email: </span>
<input type="email" name="email", required="true">
<br>
Expand Down Expand Up @@ -824,6 +837,46 @@ Session or cookie usually resides on client side. We will go one step further an
{% include note.html content="To run application localy, you need to have Redis server running on your local machine. Refer to Redis documentation for [installation details](https://redis.io/documentation)." %}
=======

### MongoDB

Before we dive into login/register python machinery I would like to address few topics related to this issue. First is database choice. I decided to store user provided information and data received from social media providers in NoSQL database - [MongoDB][mongo]. Main reason is that different providers have different data models. Friends, followers lists, text or media content of the posts, software repositories. Variety makes nearly impossible to fit them in some sane common relational database. In MongoDB, JSON like format of the data is playing nicely with the data format given by providers (API requests return JSON responses). JSON can be easily manipulated in python and converted tot he dictionary container. It is also very easy to store and manipulate graph-type data. To communicate with db we will use excellent Flask extension: [`flask_pymongo`][flpymg]. Pip install it `pip install flask_pymongo` if package is not installed on your system.

<br>
{% include note.html content="This step assumes, you have MongoDB server up and running on your local machine. Refer to [__MongoDB documentation__](https://docs.mongodb.com/manual/administration/install-community/) for installation details." %}

First lets register PyMongo extension (and add `flask_pymongo==0.5.1` to the requirements list in production):

__/app/extensions.py__
{% highlight python linenos %}
...
from flask_pymongo import PyMongo

...
mongo = PyMongo()
{% endhighlight %}

And add to `register_extensions()` in main application:

__/app/app.py__
{% highlight python linenos %}
from app.extensions import debug_toolbar, mongo
from app import public

...
def register_extensions(app):
"""Register Flask extensions."""
debug_toolbar.init_app(app)
app.logger.debug("Debug toolbar initialized")
mongo.init_app(app)
app.logger.debug("Debug mongo initialized")
return None
{% endhighlight %}


This will attach PyMongo db to the current app using default name or name specified in `settings.py` file.



### Sessions

Sometimes URL's contain additional parameters submitted in the URL (i.e `http://www.domain.com/endpoint?key=value`). One can access them via Flask request object (`request.args` attribute) and store them in the cookies attribute (`request.cookies`) for later usage. However using cookies is not preferred to store requests data, especially sensitive one like credentials or authorization tokens, therefore it is recommended to use more secure solution and it is__session__.
Expand Down Expand Up @@ -967,6 +1020,7 @@ To restrict
2. security with bcrypt - password passed in POST http call.
3.

<<<<<<< HEAD
<<<<<<< HEAD
Before we dive into login/register python machinery I would like to address few topics related to this issue. First is database choice. I decided to store user provided information and data received from social media providers in NoSQL database - [MongoDB][mongo]. Main reason is that different providers have different data models. Friends, followers lists, text or media content of the posts, software repositories. Variety makes nearly impossible to fit them in some sane common relational database. In mongo, JSON like format of the data is playing nicely with the data format given by providers (API requests return JSON responses). JSON can be easily manipulated in python and converted tot he dictionary container. It is also very easy to store and manipulate graph-type data. To communicate with db we will use excellent Flask extension: [`flask_pymongo`][flpymg]. Pip install it `pip install flask_pymongo` if package is not installed on your system.
=======
Expand Down Expand Up @@ -1006,6 +1060,8 @@ def register_extensions(app):


This will attach PyMongo db to the current app using default name or name specified in configurtion file.
=======
>>>>>>> 7b8ed81e246d72878f051ae568b6b13377af597c
<<<<<<< HEAD
=======
Expand Down
26 changes: 0 additions & 26 deletions _drafts/travis-ci-python.md

This file was deleted.

27 changes: 27 additions & 0 deletions _drafts/twitter-bot-2017.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
layout: post
author: Michal Dyzma
title: Jak napisać bota Twittera z panelem administracyjnym - projekt igła
date: 2017-12-14 18:40:08
comments: true
mathjax: false
categories: python Flask Twitter, Bot
keywords: python, Flask, Twitter, Bot
---

Dzisiaj przedstawię jak wygląda pisanie komercyjnego softu. Pełne TDD/BDD do tego Flask i Twitter. Przedmitem wpisu będzie bot automtyzujący różne żmudne czynności w serwisie Twitter. Może masz dziewczynę, która uwiebia, kiedy lajkujesz jej posty posty. Albo jesteś szefem zatroskanym o wizerunek firmy i chciałbyś nieco "podkręcić wyniki". Jesteś w dobrym miejscu.



## Wtstęp

Budowa będzie miała pięć etapów:

1. Dokumentacja (SDD)
2. Konfiguracja środowiska deweloperskiego i produkyjnego
3. Kodzenie rozwiązań w TDD/BDD
4. Wypuszczenie na produkcję

## Specyfikacja, SDD

Co będzie robił Tweebot?
File renamed without changes.
9 changes: 2 additions & 7 deletions _posts/2017-06-07-social-media-analysis-part-I.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ Flask application presenting social media accounts analysis in form of dashboard

## Series consists of:

* [Social media analysis with Flask, Part I]({{site.url}}/2017/06/07/social-media-analysis-part-I/) (Setting environment, flask, Travis CI/Heroku CD )
* [Social media analysis with Flask, Part II]({{site.url}}/2017/07/12/social-media-analysis-part-ii/) (Templates, login/register mechanism, data storage)
* [Social media analysis with Flask, Part I]({{site.url}}{% post_url 2017-06-07-social-media-analysis-part-I %}) (Setting environment, flask, Travis CI/Heroku CD )
* [Social media analysis with Flask, Part II]({{site.url}}{% post_url 2017-07-12-social-media-analysis-part-ii %}) (Templates, login/register mechanism, data storage)


<!-- * [Social media analysis with Flask, Part III]({{site.url}}/2017/08/17/social-media-analysis-part-iii) (Twitter data analysis)
* [Social media analysis with Flask, Part IV]({{site.url}}/2017/09/09/social-media-analysis-part-iv/) (Twitter data analysis)
* [Social media analysis with Flask, Part V]({{site.url}}/2017/10/18/social-media-analysis-part-v/) (Facebook data analysis)
* [Social media analysis with Flask, Part VI]({{site.url}}/2017/11/05/social-media-analysis-part-vi/) (GitHub data analysis)
-->
## Part I

0. [Application description](#application-description)
Expand Down
Loading

0 comments on commit 1ae87bb

Please sign in to comment.