#!/usr/bin/env python import datetime, json, os, random, time # Set the `project` variable to a Google Cloud project ID. project = 'winged-acolyte-429907-h2' pubsub_id = 'retail_pubsub' NAMES = ['Asawathongchai','Boonnit','Chaicharee','Chaithep','Chanin','Choowa','Damrongdech', 'Dibbayawan','Fuangkhon','Gounee','Kamlangdee','Kewalin','Kim','Kitcharanon','Le','Natadol', 'Nattapat','Ngamsapmanee','Nutthun','Olanchantarothai','Pachokeklungtanakul','Paphawarin', 'Patcharapon','Pattarasuda','Phansor','Phuthanapalawat','Pinyada','Piyabute','Polsarut', 'Raksit','Rangsikosai','Rangsiman','Rattanasithon','Rattanasomboon','Riensavapak','Ruqi', 'Saelee','Saimakkha','Sakoolkaew','Sereephap','Sippakorn','Siraphat','Sittisak','Smith', 'Sornsawan','Sudmann','Tanadach','Thongathip','Toeysiriset','Wachirawit','Wanthongchai', 'Wasinthorn','Wattanapun','Wilaisaranun','Wisawanan','Witchawin','Wongpakdee','Wongsathorn', 'Xiangyu','Xinluo','Yang','Yanisa','Zhang',] CITIES = ['Washington', 'Springfield', 'Franklin', 'Greenville', 'Bristol', 'Fairview', 'Salem', 'Madison', 'Georgetown', 'Arlington', 'Ashland',] STATES = ['MO','SC','IN','CA','IA','DE','ID','AK','NE','VA','PR','IL','ND','OK','VT','DC','CO','MS', 'CT','ME','MN','NV','HI','MT','PA','SD','WA','NJ','NC','WV','AL','AR','FL','NM','KY','GA','MA', 'KS','VI','MI','UT','AZ','WI','RI','NY','TN','OH','TX','AS','MD','OR','MP','LA','WY','GU','NH'] PRODUCTS = ['Product 2', 'Product 2 XL', 'Product 3', 'Product 3 XL', 'Product 4', 'Product 4 XL', 'Product 5', 'Product 5 XL',] while True: first_name, last_name = random.sample(NAMES, 2) data = { 'event_timestamp': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'tr_time_str': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'first_name': first_name, 'last_name': last_name, 'city': random.choice(CITIES), 'state':random.choice(STATES), 'product': random.choice(PRODUCTS), 'amount': float(random.randrange(50000, 90000)) / 100, } # For a more complete example on how to publish messages in Pub/Sub. # https://cloud.google.com/pubsub/docs/publisher message = json.dumps(data) command = "gcloud --project={} pubsub topics publish {} --message='{}'".format(project, pubsub_id, message) print(command) os.system(command) time.sleep(random.randrange(1, 5))