This is the code repository for Python Social Media Analytics, published by Packt. It contains all the supporting project files necessary to work through the book from start to finish.
Social Media platforms such as Facebook, Twitter, Forums, Pinterest, and YouTube have become part of everyday life in a big way. However, these complex and noisy data streams pose a potent challenge to everyone when it comes to harnessing them properly and benefiting from them. This book will introduce you to the concept of social media analytics, and how you can leverage its capabilities to empower your business.
Right from acquiring data from various social networking sources such as Twitter, Facebook, YouTube, Pinterest, and social forums, you will see how to clean data and make it ready for analytical operations using various Python APIs. This book explains how to structure the clean data obtained and store in MongoDB using PyMongo. You will also perform web scraping and visualize data using Scrappy and Beautifulsoup.
Finally, you will be introduced to different techniques to perform analytics at scale for your social data on the cloud, using Python and Spark. By the end of this book, you will be able to utilize the power of Python to gain valuable insights from social media data and use them to enhance your business processes.
All of the code is organized into folders. Each folder starts with a number followed by the application name. For example, Chapter02.
The code will look like the following:
{
"cells": [
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import requests\n",
"\n",
"results = []\n",
"q = \"created:>2017-01-01\"\n",
"\n",
"def search_repo_paging(q):\n",
" params = {'q' : q, 'sort' : 'forks', 'order': 'desc', 'per_page' : 100}\n",
" url = 'https://api.github.com/search/repositories'\n",
"\n",
" while True:\n",
"\n",
" res = requests.get(url, params = params)\n",
" result = res.json()\n",
" results.extend(result['items'])\n",
" params = {}\n",
"\n",
" try:\n",
" url = res.links['next']['url']\n",
" except:\n",
" break"
]
},