dailylog 8-13-20
Project TikTokAPI continues
- added this code so we can get daily blips
from datetime import datetime
today = str(datetime.now().date())
filename = '{}_trending.csv'.format(today)
trending_videos_df.to_csv(filename,index=False)
THINGS WE NEED:
- Cron job
- This needs webserver
- Webserver we are comfortable with is Node
- Can Node run python?
- SO says yes
HOW TO GENERATE A RANDOM NUMBER (via python) ONCE EVERY MINUTE (via node + express)
yarn add node-cron fs
random_number.py
import sys
import random
data = random.random()
print(data)
sys.stdout.flush()
index.js
const express = require("express");
const cron = require("node-cron");
const fs = require("fs");
const spawn = require("child_process").spawn;
const app = express();
app.get("/", (req, res) => {
res.send("I love kittens!");
});
cron.schedule("* * * * *", function () {
console.log("running a task every minute");
const myPythonScript = spawn("python", ["./random_number.py"]);
myPythonScript.stdout.on("data", (data) => {
console.log("getting here");
console.log(data);
// Do something with the data returned from python script
});
});
const port = process.env.PORT || 5000;
app.listen(port);