Writing a screencast blog with Flask

I read somewhere that the best way to learn a programming language, and to get better at coding is to work on projects. Open-source projects can be daunting for beginners so, it’s probably a good idea to roll your own apps for things you need personally. I really wanted to write my own blog but like I mentioned earlier, I set a deadline for the new moon/solar eclipse to launch, and I just couldn’t quite get the “pagination” working in time.

I got the idea to make a Blog for flask newbies. The idea was based on an old ruby-on-rails site I used to visit when I was trying to learn Ruby on Rails. The domain that I have purchased is flaskcast.com and basically all I’m going to do is write a simple blog website in flask that will display the YouTube videos embedded in the posts with a title and date posted. I may eventually add a discussion section for each video.

Tools
  • Python 3.6.2
  • Flask
  • Database (probably use MongoDB, as I am enjoying learning new stuff but may go with sqlite3 or postgres)
  • The Flask-MongoAlchemy extension. https://pythonhosted.org/Flask-MongoAlchemy/
  • Blueprints (to make the app modular, may need to scale it up at some point)
  • Digital Ocean for hosting
  • PyCharm
  • probably more…

The big issue I faced trying to write my own blog engine was that I had to write my own database module that utilized PyMongo. It was a learning experience, and in fact I got most of the code from a Udemy course that I had taken. I’m just not advanced enough right now to write my own pagination code that uses MongoDB. After looking at the docs for the MongoAlchemy extension, it looks like 90% of the code I had to write is already taken care of. This is copied from the docs:

from flask import Flask
from flask.ext.mongoalchemy import MongoAlchemy
app = Flask(__name__)
app.config['MONGOALCHEMY_DATABASE'] = 'library'
db = MongoAlchemy(app)

class Author(db.Document):
    name = db.StringField()

class Book(db.Document):
    title = db.StringField()
    author = db.DocumentField(Author)
    year = db.IntField()

from application import Author, Book
mark_pilgrim = Author(name='Mark Pilgrim')
dive = Book(title='Dive Into Python', author=mark_pilgrim, year=2004)

mark_pilgrim.name = 'Mark Stalone'
mark_pilgrim.save()
Flask-MongoAlchemy example

So as you can see, basically you create document objects and work with those. Looks like querying the database is really simple as well. My module required some pretty complicated RegEx that I am not comfortable writing without assistance.

Pagination appears to be pretty simple as well…

paginate(page, per_page=20, error_out=True)

Next post I will share some design ideas.

See you tomorrow!

Welcome to my blog!

This blog was inspired by https://dbader.org/, so I wanted to first and foremost give a shout-out and thanks.

About Me…

Well, I am a proud father and happy husband. I have 3 children, 2 dogs, several goldfish and a wonderful wife. I work professionally as a registered nurse case manager in the workers compensation field. I do love my job, but nursing isn’t what I set out to do…

In the mid 90’s my mother bought our first computer, a Tandy Sensation from Radio Shack….

This pretty much changed my life. I was able to tinker around on this computer at a young age 12-14 years old. I was blown away. Before this I used to try and make large outdoor antennas that could pick up radio stations from surrounding larger cities (I lived in a small rural town in the middle of nowhere). So having access to the internet, via dialup connection…was a game changer. I did in fact get in trouble as a kid because my cousin and I were using dial-up to connect to AOL and chat…the number was long distance so we ran up a very large phone bill.

I promise, as I do this I will get better at writing...I realize I suck right now.

As time went on I learned about ZDTV on our large c-band satellite system.

I literally grew up watching Leo and Kate. I learned how to mess around with Linux distros. I think my favorite around that time was Mandrake Linux, or Fedora.I went to college and a guy down the hall in my dorm built PC’s so, he helped me build my first one.

I then decided computer science was for me…this was late 90s early 2k’s. I made it about 2 years into my degree. I didn’t mention this before, but I was into music and played in a band. I actually set up a local music scene page called appalcore.org that does not exist today. I used that page as an outlet for my development interests. It was mostly PHP based stuff…but was fun to do.

I ultimately got scared of the “dot com bubble” and that I would not find a job…especially if I wanted to stay in my small rural town. So I switched majors to Nursing, having a lot of voices in my ear telling me to go into Health-care. In the meantime, I did start a web agency with a friend and we did a lot of early web-standards stuff. It was hard because we mostly pandered to our local market and being in a rural area…not really anyone gave a shit. There were a couple of real estate agencies and a restaurant or 2. I built a pretty big codeigniter project and tried to implement some early MVC stuff…but the code kind of sucked… The agency disbanded and I went on to get my nursing degree.

Fast forward 10 years or so…

I realize now that time goes by much faster than I ever did as a kid. A lot of my mistakes were thinking that something would take too long to complete…so I wouldn’t try. I look back now and a year literally seems like a day…

I have decided that life is too short not to follow what you are passionate about. Trying to make career choices based on what other people think, or what a local market dictates (there is no such thing as a local market in this day and age).

So this blog is dedicated to my rebirth as a developer. I started out on this path, and I wandered off. It seemed impossible for a while that I could ever get back onto this path. Yet, here I am. I am going to use this blog as a medium for my experiences and what I am learning, and doing. Some things may be more “personal”, and less informative. I am also really into esoteric shit… so you might get some of that from time to time. I had to get this in before 8/21/17…

Python is the language of choice. I had intended this blog to be hand coded in python, and actually started on the code using Flask, MongoDB… but it is imperative this be released on/before 8/21/17 for metaphysical reasons. New moons are powerful for new ventures….this one specifically. I couldn’t quite meet the deadline, and I actually had the domain and a hosting account ready to go…so I went with a basic wordpress for now.

The project I am going to produce based on the above code is FlaskCasts, www.flaskcasts.com. This is going to be a screencast/vlog/blog type situation. I am going to use this to put out videos on general web development issues and hopefully gain some traction in the community.

Hit me up via email: me@eddiegrey.com

PEACE!

Bear with me...I'll get better at writing.