-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofficial_course.py
36 lines (34 loc) · 1.21 KB
/
official_course.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
from xata.client import XataClient
import config
import cogenai
import base64
import table_init
import asyncio
def official_course(file):
xata = XataClient(api_key=config.xata_key, db_url=config.xata_endpoint)
print('Initialising table')
asyncio.run(table_init.init_db())
# Generate the course files
cogenai.generate_course(file)
# Encode the file contents to base64
input("Check files and press 'Enter' if done")
with open(f'{file}.by.gen.txt') as f: by = f.read()
with open(f'{file}.eng.gen.txt') as f: en = f.read()
with open(f'{file}.ru.gen.txt') as f: ru = f.read()
en_file_base64 = base64.b64encode(en.encode(encoding="utf-8")).decode('utf-8')
ru_file_base64 = base64.b64encode(ru.encode(encoding="utf-8")).decode('utf-8')
by_file_base64 = base64.b64encode(by.encode(encoding='utf-8')).decode('utf-8')
# Prepare the record to be inserted
record = xata.records().insert("courses_official", {
"en": {
"base64Content": en_file_base64,
},
"ru": {
"base64Content": ru_file_base64,
},
"by": {
'base64Content': by_file_base64,
}
})
return record
print(official_course('python.yaml'))