App Infrastructure

Config

Aim
To allow users to enter their own playlist and have the app remember the playlist from session to session on one device.
Method
I followed this tutorial (Grinberg, 2017). This adds a form to the site, but doesn’t do anything further with the form entries. Grinberg’s tutorial goes on to describe how to create a full login system using SQLAlchemy, but I don’t need anything as complex for my aim.

I used the WTForms module to create the form fields and collect their entries, for example playlist_url = form.playlist.data.

A username is generated for each user which consists of the ID of the playlist they entered plus a randomly generated text string. This is saved as a cookie on their device, and into the database along with the Playlist URL and ID.

WTForms has some validation utilities, and it catches entries that don’t seem to be a URL.

Once the user has entered their playlist, they are redirected to the index page, where a message is flashed saying “The NAME playlist has been added”, where the name is extracted from the YouTube API given the playlist ID.

Standard
App Infrastructure, Code

Tips and Tricks #2

  • To remove a directory that contains other files or directories, use rm -r mydir
  • To add a CSV to MongoDB, use mongoimport –uri mongodb://maryann:<password>@ds159845.mlab.com:59845/tube –collection dates –type csv –headerline –file dates.csv –ignoreBlanks
  • Generate a random string if Secrets module isn’t working
  • Automatically stage updates in Git
  • Create a back button in the web page with <button onclick=”goBack()”>Go Back</button> and<script>
    function goBack() {
        window.history.back();
    }
    </script>
Standard
Content

Trends in Children’s Video Content

It is no revelation that video content for children has undergone changes in recent years, with interconnected causes stemming directly and indirectly from growth in the use of mobile devices.

Increased distribution opportunities via the internet has led to the possibility of producing content for foreign countries, if the language barrier can be overcome. Some production companies find it worthwhile to create non-native language versions of their shows, while others have created shows without language for viewing anywhere.

Advertising via platforms such as YouTube/Google offer greater targeting opportunities but regulatory changes and a gathering privacy movement, combined with a need to police abusive content, mean that advertising revenue is no longer a guaranteed support for long tail (Anderson, 2006) content producers.

The advent of the smartphone and tablet have meant that young children can control their own video viewing with the use of apps, often in simplified versions for children, instead of relying on editorially curated programming at particular times. The availability of smartphones has also democratised content creation even further than the consumer camcorder did, with child users and their parents able to document their lives and media use, and create animation using toys and games.

Large broadcasters such as the BBC have been forced to react to these trends, while internet-native broadcasters like Netflix have evolved in parallel.

Standard
App Infrastructure, Tools

Deployment

Deploying a Python app isn’t as simple as uploading and installing PHP apps such as WordPress. WordPress is installed on a server and database, but with Python you need to supply all that yourself. I have done much of the development on CodeAnywhere which can provide a container, a virtual computer which is fired up when you want to use it which is suitable for testing purposes. Flask creates a very lightweight web server but it isn’t suitable for production use, so a more robust solution needs to be found.

As already mentioned the developer needs to organise a rented virtual computer with server software and a database. I have set up a database on MongoDB provider MLab instead of installing MongoDB on the development container, as then I don’t have to change anything when deploying to a publicly accessible URL. A traditional web server is online 100% of the time and processes HTTP requests as they come in, some of which will time out (Jones, 2018). Plus it is a long process to set up a server from scratch.

Serverless

Many web apps can now be deployed using third-party services and “custom code run on ephemeral containers” (Maruti Techlabs, 2017) such as Amazon Web Services’ Lambda. Zappa is a tool that makes it easy to run Python web apps on Lambda. From the documentation:

“With Zappa, each request is given its own virtual HTTP “server” by Amazon API Gateway. AWS handles the horizontal scaling automatically, so no requests ever time out. Each request then calls your application from a memory cache in AWS Lambda and returns the response via Python’s WSGI interface. After your app returns, the “server” dies.” (Jones, 2018)

CianTube is already using a third-party database and the YouTube API so it is a good candidate for using Lambda to serve the core app.

I cloned the app from GitHub and installed it on my Mac as I needed to install the AWS credentials on the machine that the app is running on locally and I couldn’t do that on the CodeAnywhere container. Zappa needs to be installed in a Virtual Environment, which isolates the app from the rest of the system so it can’t do any damage if anything goes wrong. Once this is done, the terminal command zappa init sets up the deployment settings, including defining one or more stages so you can run an app on the web without exposing it to users before it is properly tested.

To deploy the app the command zappa deploy stagename is used, which packages and uploads the local files, and when complete the URL of the app is displayed. To update, the command zappa update production is used.

zappa

I did this and the app worked on the web without a problem.

zappa_web

References

Maruti Techlabs. (2017). What is Serverless Architecture? What are its criticisms and drawbacks?. [online] Available at: https://medium.com/@MarutiTech/what-is-serverless-architecture-what-are-its-criticisms-and-drawbacks-928659f9899a [Accessed 24 Apr. 2018].

Jones, R. (2018). Miserlou/Zappa. [online] Available at: https://github.com/Miserlou/Zappa#about [Accessed 24 Apr. 2018].

Standard