You can download this code by clicking the button below.
This code is now available for download.
This function defines a Luigi task that generates a JSON report containing the current date and a random number.
Technology Stack : Luigi, random, datetime, json
Code Type : Luigi Task
Code Difficulty : Intermediate
def random_task():
import luigi
import random
import datetime
import json
class GenerateReport(luigi.Task):
def output(self):
return luigi.LocalTarget("report.json")
def run(self):
with self.output().open("w") as f:
data = {
"date": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"random_number": random.randint(1, 100)
}
json.dump(data, f)
return GenerateReport