Files
SecondBrain/90 Library/Programming/Ruby On Rails/API импорт в Rails через runner.md
T
2026-05-31 10:18:48 +03:00

75 lines
2.2 KiB
Markdown

---
status: seed
type: guide
tags:
- programming
- ruby-on-rails
- api
created: 2026-05-25
updated: 2026-05-25
source: '[[Работа с API для проекта Attendance Mephi]]'
aliases:
- API импорт в Rails через runner
---
# API импорт в Rails через runner
Памятка по ручному запуску импортов в [[Ruby On Rails - MOC]]-проекте Attendance Mephi для [[НИР]].
## Контекст
Импорт запускается через `bin/rails runner`:
```sh
/home/ada/.local/bin/mise exec ruby -- bin/rails runner '...'
```
Актуальный семестр берется из `Term.actual`. Для старта `2026-02-07` код семестра: `20252`.
## Credentials
```yaml
api:
home_mephi:
host:
code:
token:
students_mephi:
host:
username:
password:
```
См. также: [[Rails credentials edit не открывает редактор]].
## Endpoints
```text
GET {home_mephi.host}/study_groups.json?term_code=20252&code=...&token=...
GET {home_mephi.host}/tutors.json?term_code=20252&code=...&token=...
GET {students_mephi.host}/get_list_by_group_name?group=...&term=20252
GET {home_mephi.host}/tutors/{staff_id}/schedules.json?term_code=20252&date=YYYY-MM-DD&code=...&token=...
```
`students_mephi` использует Basic Auth: `username/password`.
## Ручная загрузка
```sh
/home/ada/.local/bin/mise exec ruby -- bin/rails runner 'ImportGroupsService.execute'
/home/ada/.local/bin/mise exec ruby -- bin/rails runner 'ImportTutorsService.execute'
/home/ada/.local/bin/mise exec ruby -- bin/rails runner 'ImportStudentsService.execute'
/home/ada/.local/bin/mise exec ruby -- bin/rails runner 'term = Term.actual; ImportDisciplineService.execute(nil, term)'
```
Расписание на сегодня:
```sh
/home/ada/.local/bin/mise exec ruby -- bin/rails runner 'term = Term.actual; ImportScheduleService.execute(Date.today, term)'
```
Расписание за весь семестр до сегодня:
```sh
/home/ada/.local/bin/mise exec ruby -- bin/rails runner 'term = Term.actual; finish = [term.get_finish_date, Date.today].min; (term.start_date..finish).each { |date| ImportScheduleService.execute(date, term) unless date.wday == 0 }'
```