dailylog 8-11-20

2 minute read

from TikTokApi import TikTokApi
import pandas as pd
api = TikTokApi()


def simple_dict(tiktok_dict):
    to_return = {}
    to_return['user_name'] = tiktok_dict['author']['uniqueId']
    to_return['user_id'] = tiktok_dict['author']['id']
    to_return['video_id'] = tiktok_dict['id']
    to_return['video_desc'] = tiktok_dict['desc']
    to_return['video_time'] = tiktok_dict['createTime']
    to_return['video_length'] = tiktok_dict['video']['duration']
    to_return['video_cover'] = tiktok_dict['video']['cover']
    to_return['video_cover_dynamic'] = tiktok_dict['video']['dynamicCover']
    to_return['video_link'] = 'https://www.tiktok.com/@{}/video/{}?lang=en'.format(
                to_return['user_name'], to_return['video_id'])
    to_return['n_likes'] = tiktok_dict['stats']['diggCount']
    to_return['n_shares'] = tiktok_dict['stats']['shareCount']
    to_return['n_comments'] = tiktok_dict['stats']['commentCount']
    to_return['n_plays'] = tiktok_dict['stats']['playCount']
    return to_return



n_trending = 100
trending_videos = api.trending(count=n_trending)
trending_videos = [simple_dict(v) for v in trending_videos]
trending_videos_df = pd.DataFrame(trending_videos)
trending_videos_df.to_csv('trending.csv',index=False)

2. Quickly import and export it as json

df = pd.read_csv('trending.csv')
result = df.to_json('trending.json', orient="records")
result

3. Upload to github for temp hosting

targetUrl =
  "https://raw.githubusercontent.com/danielcaraway/danielcaraway.github.io/master/assets/data/trending.json";
let response = await fetch(targetUrl);
let data = await response.json();
justVideos = data.map((tiktok) => tiktok.video_link);

INSTIGATOR:

OMG TIKTOKAPI IS SO EXCITING!

PROBLEM:

I don’t want to install the API on my actual machine for… reasons?

SOLUTION:

Virtual environments!!

PROBLEM:

Jupyter notebook doesn’t play nice with virtual environments

SOLUTION:

Simply run what I need inside the console and pull it into Jupyter Notebook!!

PROBLEM:

This additional step is a barier (sp?) to entry

SOLUTION:

Well, what is our end goal? To see and keep the daily trending tiktoks? Yes? I think so?

WE WANT TRENDING DATA OVER TIME?

How to schedule your Python Scripts on Mac and Windows

Convert Python Scripts to executable applications for Mac and Windows

(2) Getting a python script to automatically run daily : applehelp

(2) Id like my python script to run daily at a certain time. Suggestions on how to go about this? : learnpython

Linux crontab command help and examples

Linux crontab command help and examples

[Mac crontab: Creating MacOS launchd alvinalexander.com](https://alvinalexander.com/mac-os-x/mac-osx-startup-crontab-launchd-jobs/)

Creating a Launch Agent that provides an XPC service on macOS using Swift

Schedule jobs using launchd

A launchd Tutorial

[How To Create and Run Scheduled Jobs with Node.js DigitalOcean](https://www.digitalocean.com/community/tutorials/nodejs-cron-jobs-by-examples)

[How to Collect Data from TikTok (Tutorial) by Jack Bandy Jul
2020 Towards Data Science](https://towardsdatascience.com/how-to-collect-data-from-tiktok-tutorial-ab848b40d191)  

This is an example of a TikTok dictionary returned by davidteather/TikTok-Api

tiktok_demo.py

TikTok-Api/tiktok.py at master · davidteather/TikTok-Api

David Teather - YouTube

[JavaScript Algorithms and Data Structures Masterclass Udemy](https://www.udemy.com/course/js-algorithms-and-data-structures-masterclass/learn/lecture/8344878#overview)

Intro to Algorithms: CHAPTER 23: ELEMENTARY GRAPH ALGORITHMS

Intro to Algorithms: PART VI: Graph Algorithms

[The Modern Javascript Bootcamp Course (2020) Udemy](https://www.udemy.com/course/javascript-beginners-complete-tutorial/learn/lecture/17007310#questions/12087244)

aaroncaraway/flaskintro: Tiny Flask App!

How can I run a python script from within Flask - Stack Overflow

Turning a Python script into a website - PythonAnywhere News

Home Page - Select or create a notebook

Using Virtual Environments in Jupyter Notebook and Python - Parametric Thoughts

[Jupyter Notebook in a virtual environment (virtualenv) by Emmanuel Medium](https://medium.com/@eleroy/jupyter-notebook-in-a-virtual-environment-virtualenv-8f3c3448247)

Lauching a Jupyter notebook from within a virtual environment · Vicki Boykis

python - Converting Epoch time into the datetime - Stack Overflow

How to convert between date and Unix timestamp in Excel?

[Running ChromeDriver with Python Selenium on Heroku by Michael Browne Medium](https://medium.com/@mikelcbrowne/running-chromedriver-with-python-selenium-on-heroku-acc1566d161c)

node.js - How to use Selenium Webdriver on Heroku? - Stack Overflow