repl.it
Python

No description

fork
loading
Files
  • main.py
  • names.json
  • perm.py
  • rx-4d5ce-517b9c7385a6.json
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from itertools import permutations
import requests
import os

# Initialize on Google Cloud Platform

import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore

# Use the application default credentials
project_id = os.getenv('FB_PROJECT_ID')
# Use a service account
cred = credentials.Certificate('./rx-4d5ce-517b9c7385a6.json')
firebase_admin.initialize_app(cred)

db = firestore.client()


abc = "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"

perms = sorted(list(set(permutations(abc, 3))))

all_perm = []

for p in perms:
  s = "".join(p)
  all_perm.append(s)

print(len(all_perm))

# q = all_perm[3]


count_exists = 0
count_inserts = 0
count_perms = 0
total_perms = len(all_perm)

def progress():
  global count_perms
  global total_perms

  return (count_perms/total_perms)*100


for q in all_perm:
  count_perms += 1
  if count_perms < 2000:
    continue
    
  url = os.getenv('BASE_URL') + q

  user_agent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/69.0.3497.105 Mobile/15E148 Safari/605.1'
  headers = {'User-Agent': user_agent}
  r = requests.get(url, headers=headers)
  docs = r.json()
  # print(q, docs)

  for d in docs:
    aa_id = int(d['id'])
    doc_id = hex(aa_id)[2:]
    label = d['label']
    value = d['value']
    rel = d['rel']

    doc_ref = db.collection(u'medications').document(doc_id)
    try:
      doc_ref.create({
          u'label': label,
          u'value': value,
          u'aa_id': aa_id,
          u'rel': rel
      })
      count_inserts += 1
    except:
      count_exists += 1
      pass
  
  print("new", count_inserts)
  print("already exist", count_exists)
  print("Perm: ", q, count_perms)
  print("Progress: ", progress())


?