Skip to content

Instantly share code, notes, and snippets.

@dmcgrath
Created January 31, 2019 17:21
Show Gist options
  • Save dmcgrath/390e0a2c10f968f75e1802e9a49dcac1 to your computer and use it in GitHub Desktop.
Save dmcgrath/390e0a2c10f968f75e1802e9a49dcac1 to your computer and use it in GitHub Desktop.
from google.cloud import firestore
from time import sleep
# Add a new document
db = firestore.Client()
doc_ref = db.collection(u'live_news').document(u'2019-01-31')
def pad_message(m):
pad_size = len(m)
return u'\u00A0'*pad_size + m + u'\u00A0'*(pad_size+1)
def masked_message(m, pos):
pad_size = len(m) // 3
return m[pos:pos+pad_size]
all_messages = ["As modern application development moves"
, "towards a serverless future"
, "we're pleased to announce the General Availability (GA) of"
, "Cloud Firestore, our serverless, NoSQL document database."
, "We're also making it available in"
, "10 new locations to complement the existing 3"
, "announcing a big price drop for most regional instances"
, "and enabling integration with Stackdriver."]
message_count = 0
for message in all_messages:
padded = pad_message(message)
scroll_length = len(message) * 2
for x in range((scroll_length+3)//3):
doc_ref.set({u'news': masked_message(padded, x*3)}, merge=True)
sleep(0.2)
message = message.replace("Cloud Firestore","☁️🔥🏪")
message = message.replace("10","🔟")
message = message.replace("3","3️⃣")
message = message.replace("big price drop", "💰🔻")
message = message.replace(" serverless,", "")
message = message.replace("complement", "+")
message = message.replace("complement", "+")
if (message_count == 2):
doc_ref.set({u'GA': True}, merge=True)
else:
doc_ref.set({u'news'+str(message_count): message}, merge=True)
message_count += 1
doc_ref.set({u'news': u'cloud.google.com/firestore'}, merge=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment