Skip to content

Instantly share code, notes, and snippets.

@NarekChang
Created October 2, 2018 10:55
Show Gist options
  • Save NarekChang/dfc015d1d2e19d5a20f1746fd9bc0e09 to your computer and use it in GitHub Desktop.
Save NarekChang/dfc015d1d2e19d5a20f1746fd9bc0e09 to your computer and use it in GitHub Desktop.
import firebase_admin
import json
import datetime
import random
import sys
import os
from firebase_admin import credentials
from firebase_admin import firestore
from babel.dates import format_date
signs = [
"Aquarius",
"Aries",
"Cancer",
"Capricorn",
"Gemini",
"Leo",
"Libra",
"Pisces",
"Sagittarius",
"Scorpio",
"Taurus",
"Virgo"
]
sections = [
"Career",
"Daily Report",
"Health",
"Mood",
"Romantic"
]
# Use a service account
cred = credentials.Certificate('astrology-96fd5-firebase-adminsdk-vrmht-3b9b62b239.json')
firebase_admin.initialize_app(cred)
def getText(path):
print(path)
with open(path, 'r') as myfile:
data = myfile.read()
return data
def getPaths(year, month, day, sign):
if sign == "Gemini":
sign = "Twins"
date = datetime.date(year, month, day)
ruDate = format_date(date, "d MMMM", locale="ru_RU").lower()
enDate = format_date(date, "d_MMMM", locale="en_US").lower()
return [os.path.join(sys.argv[1], section, ruDate, sign + "_" + enDate + ".txt") for section in sections]
db = firestore.client()
ref = db.collection("horoscope")
root = sys.argv[1]
month = 11
year = 2018
for sign in signs:
for day in range(1, 31):
date = datetime.date(year, month, day)
paths = getPaths(year, month, day, sign)
texts = list(map(lambda p: getText(p), paths))
data = {'date': date.isoformat(), 'romantic': texts[4], 'daily': texts[1], 'mood': texts[3], 'career': texts[0], 'health': texts[2]}
doc_ref = ref.document(sign)
doc_ref.collection("daily").document(date.isoformat()).set(data)
print("{} {}".format(date.isoformat(), sign))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment