Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d2c187e
add sheet to yadisk table adding logic
HadronCollider Oct 13, 2024
826d682
integrate yadisk logic to moodle export
HadronCollider Oct 13, 2024
38e6bca
dont push to google if no table/sheet id
HadronCollider Oct 13, 2024
f160724
dont push to google if no google_token in args
HadronCollider Oct 13, 2024
e85ab21
if cls.args specified write data to sheets document
HadronCollider Oct 13, 2024
30632f8
move utils from scripts to moodle_export
HadronCollider Oct 13, 2024
3dc378d
add openpyxl to moodle_export requirements
HadronCollider Oct 13, 2024
d74564b
cp yadisk_manager.py to moodle_export
HadronCollider Oct 13, 2024
3eb8b5c
update yadisk version
HadronCollider Oct 13, 2024
392465a
yatoken as args to write_sheet_to_file
HadronCollider Oct 13, 2024
f286db4
yatoken as args to DiskManager
HadronCollider Oct 13, 2024
f62dd79
update default CSV_DELIMITER in moodle_export
HadronCollider Oct 13, 2024
30df79f
change write mode for logfile
HadronCollider Oct 21, 2024
3367341
container stdout to file (error to console)
HadronCollider Oct 21, 2024
674fdfd
fix indent for google sheet export
HadronCollider Oct 21, 2024
0562868
update check_export yo yadisk
HadronCollider Dec 16, 2024
311738e
update required args for checker_export
HadronCollider Dec 16, 2024
dcc460b
add openpyxl to requirements (checker_export)
HadronCollider Dec 16, 2024
708e04a
update yadisk version (checker_export requirements)
HadronCollider Dec 16, 2024
887ea84
update load_data_from_dis
HadronCollider Dec 16, 2024
5a17ef8
update add_csv_to_table logic
HadronCollider Dec 16, 2024
926af5e
update add_csv_to_table (split rows)
HadronCollider Dec 16, 2024
a48b857
DIS export to csv file
HadronCollider Dec 16, 2024
2d39cc7
Update moodle_export.utils.py (clear sheet instead remove)
HadronCollider Dec 18, 2024
748c9aa
Update checker_export.utils.py (clear sheet instead remove)
HadronCollider Dec 18, 2024
be48a3e
clear sheet (insert_rows with 0)
HadronCollider Dec 18, 2024
c12e307
download_sheet_to_pdf -> download_sheet (file extension as arg)
HadronCollider Dec 22, 2024
7ce4f43
update download_sheet args
HadronCollider Dec 22, 2024
83a3561
update duplicateSheetsToYadisk logs
HadronCollider Dec 22, 2024
cf9104b
update wget for download_sheet
HadronCollider Dec 22, 2024
7cdf2ea
update abs_disk_path in upload_file_to_disk
HadronCollider Dec 22, 2024
904e5e6
update duplicateSheetsToYadisk
HadronCollider Dec 22, 2024
5906eb4
update duplicateSheetsToYadisk
HadronCollider Dec 22, 2024
4d81297
fix duplicateSheetsToYadisk
HadronCollider Dec 22, 2024
e6952c2
rm debug logs
HadronCollider Dec 22, 2024
1efaf5c
add error handling in export_courses.sh
HadronCollider Feb 6, 2025
100c880
if to case (export_courses.sh)
HadronCollider Feb 6, 2025
afd7cd5
Merge branch 'main' into dev
HadronCollider Feb 6, 2025
d4d6be1
Merge branch 'main' into dev
HadronCollider Feb 7, 2025
7349a4e
checker_export: sheet_id to sheet_name
HadronCollider Apr 25, 2025
54050ee
improve export_courses.sh (implement checker export and rename env var)
HadronCollider Apr 25, 2025
5ca8d8f
Merge branch 'main' into dev
HadronCollider Apr 25, 2025
e13af25
add workflows
HadronCollider Apr 25, 2025
c905a31
rm comment in Dockerfile (stepik_export)
HadronCollider Apr 25, 2025
0398cb7
rename sheet_id to sheet_name
HadronCollider Apr 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI

on: pull_request

jobs:
build:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- name: Build stepik_export image
if: ${{ !cancelled() }}
run: |
./build.sh stepik_export
- name: Build moodle_export image
if: ${{ !cancelled() }}
run: |
./build.sh moodle_export
- name: Build checker_export image
if: ${{ !cancelled() }}
run: |
./build.sh checker_export
15 changes: 15 additions & 0 deletions .github/workflows/label_merge_conflicts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: 'Check for merge conflicts'

on: [push]

jobs:
find_conflicts:
runs-on: ubuntu-22.04

steps:
- uses: mschilde/auto-label-merge-conflicts@master
with:
CONFLICT_LABEL_NAME: "has conflicts"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAX_RETRIES: 5
WAIT_MS: 5000
2 changes: 1 addition & 1 deletion checker_export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
## Инструкция по запуску скрипта

```bash
python3 exporter.py [-h] [--google_token GOOGLE_TOKEN] --checker_token CHECKER_TOKEN [--checker_filter CHECKER_FILTER] --table_id TABLE_ID --sheet_id SHEET_ID [--yandex_token YANDEX_TOKEN --yandex_path YANDEX_PATH]
python3 exporter.py [-h] [--google_token GOOGLE_TOKEN] --checker_token CHECKER_TOKEN [--checker_filter CHECKER_FILTER] --table_id TABLE_ID --sheet_name SHEET_NAME [--yandex_token YANDEX_TOKEN --yandex_path YANDEX_PATH]
```
10 changes: 5 additions & 5 deletions checker_export/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def parse_args():
parser.add_argument('--checker_token', type=str, required=True, help='Specify session cookie for slides-checker')
parser.add_argument('--checker_filter', type=str, required=False, help='Specify filter for slides-checker')
parser.add_argument('--table_id', type=str, required=False, help='Specify Google sheet document id (can find in url)')
parser.add_argument('--sheet_id', type=str, required=False, help='Specify title for a sheet in a document in which data will be printed')
parser.add_argument('--sheet_name', type=str, required=False, help='Specify title for a sheet in a document in which data will be printed')
parser.add_argument('--yandex_token', type=str, required=False, help='Specify Yandex token from https://oauth.yandex.ru/client/new application')
parser.add_argument('--yandex_path', type=str, required=False, help='Specify output filename on Yandex Disk')
args = parser.parse_args()
Expand All @@ -47,14 +47,14 @@ def load_data_from_dis(checker_filter, checker_token):
return csv_path, df_data


def write_data_to_table(checker_token, checker_filter, google_token, table_id, sheet_id, yandex_token=None, yandex_path=None):
def write_data_to_table(checker_token, checker_filter, google_token, table_id, sheet_name, yandex_token=None, yandex_path=None):
csv_path, df_data = load_data_from_dis(checker_filter, checker_token)

if google_token and sheet_id and table_id:
if google_token and sheet_name and table_id:
gc = pygsheets.authorize(service_file=google_token)
sh = gc.open_by_key(table_id)

wk_content = sh.worksheet_by_title(sheet_id)
wk_content = sh.worksheet_by_title(sheet_name)

wk_content.set_dataframe(df_data, 'A1', copy_head=True)

Expand All @@ -69,7 +69,7 @@ def write_data_to_table(checker_token, checker_filter, google_token, table_id, s

def main():
args = parse_args()
write_data_to_table(args.checker_token, args.checker_filter, args.google_token, args.table_id, args.sheet_id, args.yandex_token, args.yandex_path)
write_data_to_table(args.checker_token, args.checker_filter, args.google_token, args.table_id, args.sheet_name, args.yandex_token, args.yandex_path)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions moodle_export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

Получение данных и в файл, и в Google таблицу:

```python3 grades_parser.py grades_parser --moodle_token "your token" --url http://e.moevm.info --course_id "your course id"[,"id",..] --csv_path "name of file" [--percentages] [--options github] --google_token "your google token" --table_id "your table id"[,"id",..] [--sheet_id "name of sheet"[,"name",..]] ```
```python3 grades_parser.py grades_parser --moodle_token "your token" --url http://e.moevm.info --course_id "your course id"[,"id",..] --csv_path "name of file" [--percentages] [--options github] --google_token "your google token" --table_id "your table id"[,"id",..] [--sheet_name "name of sheet"[,"name",..]] ```

Получение данных и в файл, и на Яндекс Диск:

Expand All @@ -36,7 +36,7 @@

Запуск докер контейнера с параметрами:

``` docker run --rm grades_parser --moodle_token "your token" --url http://e.moevm.info --course_id "your course id"[,"id",..] --csv_path "name of file" [--percentages] [--options github] --google_token "your google token" --table_id "your table id"[,"id",..] [--sheet_id "name of sheet"[,"name",..]] ```
``` docker run --rm grades_parser --moodle_token "your token" --url http://e.moevm.info --course_id "your course id"[,"id",..] --csv_path "name of file" [--percentages] [--options github] --google_token "your google token" --table_id "your table id"[,"id",..] [--sheet_name "name of sheet"[,"name",..]] ```


## Получение Moodle Токена.
Expand Down
2 changes: 1 addition & 1 deletion moodle_export/args_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def arg_parser():
parser.add_argument('--csv_path', type=str, required=True, help='Specify path to output csv file')
parser.add_argument('--google_token', type=str, required=False, help='Specify path to google token file')
parser.add_argument('--table_id', type=lambda s: [i for i in s.split(',')], required=False, help='Specify Google sheet document id (can find in url)')
parser.add_argument('--sheet_id', type=lambda s: [i for i in s.split(',')], required=False, help='Specify title for a sheet in a document in which data will be printed')
parser.add_argument('--sheet_name', type=lambda s: [i for i in s.split(',')], required=False, help='Specify title for a sheet in a document in which data will be printed')
parser.add_argument('--yandex_token', type=str, required=False, help='Specify Yandex token from https://oauth.yandex.ru/client/new application')
parser.add_argument('--yandex_path', type=str, required=False, help='Specify output filename on Yandex Disk')
parser.add_argument('--percentages', required=False, action='store_true', help='If set then grades will be printed as percentages')
Expand Down
12 changes: 6 additions & 6 deletions moodle_export/grades_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,17 @@ def main(cls):
elif i == len(cls.args.table_id) - 1:
table_id = cls.args.table_id[i]

if cls.args.sheet_id:
for i in range(0, len(cls.args.sheet_id)):
if cls.args.sheet_name:
for i in range(0, len(cls.args.sheet_name)):
if cls.args.course_id[i] == course_id:
sheet_id = cls.args.sheet_id[i]
sheet_name = cls.args.sheet_name[i]
break
else:
sheet_id = cls.args.sheet_id[i] + ' ' + course_id
sheet_name = cls.args.sheet_name[i] + ' ' + course_id
else:
sheet_id = 'course ' + course_id
sheet_name = 'course ' + course_id

sheets.write_data_to_table(df, cls.args.google_token, table_id, sheet_id)
sheets.write_data_to_table(df, cls.args.google_token, table_id, sheet_name)

# write data to yandex disk
if cls.args.yandex_token and cls.args.yandex_path:
Expand Down
12 changes: 6 additions & 6 deletions moodle_export/sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
import args_parser


def write_data_to_table(df_data, google_token, table_id, sheet_id):
if google_token and sheet_id and table_id:
def write_data_to_table(df_data, google_token, table_id, sheet_name):
if google_token and sheet_name and table_id:
gc = pygsheets.authorize(service_file=google_token)
sh = gc.open_by_key(table_id)

try:
sh.worksheets('title', sheet_id)
sh.worksheets('title', sheet_name)
except:
sh.add_worksheet(sheet_id)
sh.add_worksheet(sheet_name)

wk_content = sh.worksheet_by_title(sheet_id)
wk_content = sh.worksheet_by_title(sheet_name)

wk_content.set_dataframe(df_data, 'A1', copy_head=True)


def main():
args = args_parser.arg_parser()
write_data_to_table(args.csv_path, args.google_token, args.table_id, args.sheet_id)
write_data_to_table(args.csv_path, args.google_token, args.table_id, args.sheet_name)


if __name__ == "__main__":
Expand Down
42 changes: 24 additions & 18 deletions scripts/export_courses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# )
# system: "moodle" - Предмет,1zG21U9zJHIkfAM5ejd8WBw,Онлайн-курс,moodle,course_id
# system: "stepik" - Предмет,1zG21U9zJHIkfAM5ejd8WBw,Онлайн-курс,stepik,course_id,class_id
# system: "dis" - Предмет,1zG21U9zJHIkfAM5ejd8WBw,Онлайн-курс,dis,filter
# exportCourses "${exports[@]}"


Expand All @@ -32,31 +33,36 @@ function exportCourses() {

case "${current_export[3]}" in
"moodle")
docker run --rm -v $google_conf:/app/conf.json moodle_export_parser:latest \
--moodle_token $moodle_token --url https://e.moevm.info \
--csv_path grades --google_token conf.json \
--course_id ${current_export[4]} \
--table_id ${current_export[1]} \
--sheet_id ${current_export[2]} \
--options github >> $log_file
docker run --rm -v $EXPORTER_GOOGLE_CONF:/app/conf.json moodle_export_parser:latest \
--moodle_token $MOODLE_TOKEN --url https://e.moevm.info \
--csv_path grades --google_token conf.json \
--course_id ${current_export[4]} \
--table_id ${current_export[1]} \
--sheet_name ${current_export[2]} \
--options github >> $log_file

return_code=$?
;;
"stepik")
docker run --rm -v $google_conf:/app/conf.json stepik_export_parser:latest \
--client_id $stepik_client_id --client_secret $stepik_client_secret \
--url https://stepik.org:443/api \
--csv_path grades --google_token conf.json \
--course_id ${current_export[4]} \
--class_id ${current_export[5]} \
--table_id ${current_export[1]} \
--sheet_id ${current_export[2]} >> $log_file
docker run --rm -v $EXPORTER_GOOGLE_CONF:/app/conf.json stepik_export_parser:latest \
--client_id $STEPIK_CLIENT_ID --client_secret $STEPIK_CLIENT_SECRET \
--url https://stepik.org:443/api \
--csv_path grades --google_token conf.json \
--course_id ${current_export[4]} \
--class_id ${current_export[5]} \
--table_id ${current_export[1]} \
--sheet_name ${current_export[2]} >> $log_file

return_code=$?
;;
"checker")
echo "Not implemented"
return_code=1
"dis")
docker run --rm -v $EXPORTER_GOOGLE_CONF:/app/conf.json checker_export_parser:latest \
--checker_filter "${current_export[4]}" \
--checker_token $DIS_ACCESS_TOKEN \
--table_id ${current_export[1]} \
--sheet_name ${current_export[2]} >> $log_file

return_code=$?
;;
*)
echo "Недопустимое значение: '${current_export[3]}'"
Expand Down
1 change: 0 additions & 1 deletion stepik_export/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# syntax=docker/Dockerfile:1
FROM python:3.8-slim

WORKDIR /app
Expand Down
4 changes: 2 additions & 2 deletions stepik_export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

Получение данных и в файл, и в Google таблицу:

``` python3 stepik_parser.py --client_id "Your client id" --client_secret "Your client secret" --url https://stepik.org:443/api --course_id "Your course id" --class_id "Your class id" --csv_path grades --google_token "Path to your google token" --table_id "Your table id" [--sheet_id "Name of sheet"] ```
``` python3 stepik_parser.py --client_id "Your client id" --client_secret "Your client secret" --url https://stepik.org:443/api --course_id "Your course id" --class_id "Your class id" --csv_path grades --google_token "Path to your google token" --table_id "Your table id" [--sheet_name "Name of sheet"] ```

Получение данных и в файл, и на Яндекс Диск:

Expand All @@ -31,7 +31,7 @@

Запуск докер контейнера с параметрами:

``` docker run -v "Path to your google token":/app/ --rm stepik_parser.py --client_id "Your client id" --client_secret "Your client secret" --url https://stepik.org:443/api --course_id "Your course id" --class_id "Your class id" --csv_path grades --google_token "Path to your google token" --table_id "Your table id" [--sheet_id "Name of sheet"] ```
``` docker run -v "Path to your google token":/app/ --rm stepik_parser.py --client_id "Your client id" --client_secret "Your client secret" --url https://stepik.org:443/api --course_id "Your course id" --class_id "Your class id" --csv_path grades --google_token "Path to your google token" --table_id "Your table id" [--sheet_name "Name of sheet"] ```


## Получение Stepik Токена.
Expand Down
2 changes: 1 addition & 1 deletion stepik_export/args_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def arg_parser():
parser.add_argument('--csv_path', type=str, required=True, help='Specify path to output csv file')
parser.add_argument('--google_token', type=str, required=False, help='Specify path to google token file')
parser.add_argument('--table_id', type=str, required=False, help='Specify Google sheet document id (can find in url)')
parser.add_argument('--sheet_id', type=str, required=False, help='Specify title for a sheet in a document in which data will be printed')
parser.add_argument('--sheet_name', type=str, required=False, help='Specify title for a sheet in a document in which data will be printed')
parser.add_argument('--yandex_token', type=str, required=False, help='Specify Yandex token from https://oauth.yandex.ru/client/new application')
parser.add_argument('--yandex_path', type=str, required=False, help='Specify output filename on Yandex Disk')
args = parser.parse_args()
Expand Down
12 changes: 6 additions & 6 deletions stepik_export/sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
}]


def write_data_to_table(csv_path, google_token, table_id, sheet_id):
if google_token and sheet_id and table_id:
def write_data_to_table(csv_path, google_token, table_id, sheet_name):
if google_token and sheet_name and table_id:
gc = pygsheets.authorize(service_file=google_token)
sh = gc.open_by_key(table_id)

try:
sh.worksheets('title', sheet_id)
sh.worksheets('title', sheet_name)
except:
sh.add_worksheet(sheet_id)
sh.add_worksheet(sheet_name)

wk_content = sh.worksheet_by_title(sheet_id)
wk_content = sh.worksheet_by_title(sheet_name)

if csv_path:
df = pd.read_csv(csv_path)
Expand All @@ -33,7 +33,7 @@ def write_data_to_table(csv_path, google_token, table_id, sheet_id):

def main():
args = args_parser.arg_parser()
write_data_to_table(args.csv_path, args.google_token, args.table_id, args.sheet_id)
write_data_to_table(args.csv_path, args.google_token, args.table_id, args.sheet_name)


if __name__ == "__main__":
Expand Down
10 changes: 5 additions & 5 deletions stepik_export/stepik_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ def main():
# write data to sheets document
if args.google_token and args.table_id:
print('Send data to Google Sheets')
if args.sheet_id:
sheet_id = args.sheet_id
if args.sheet_name:
sheet_name = args.sheet_name
else:
sheet_id = 'course ' + args.course_id
sheets.write_data_to_table(csv_path, args.google_token, args.table_id, sheet_id)
print(f'Check data in your table! List name is: {sheet_id}')
sheet_name = 'course ' + args.course_id
sheets.write_data_to_table(csv_path, args.google_token, args.table_id, sheet_name)
print(f'Check data in your table! List name is: {sheet_name}')
print('********************************************************')

# write data to yandex disk
Expand Down