Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#86 Decoupling the scraper from the backend and editing the scraper to make it more versatile with different quarters #92

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
84b7ca3
Making new scraper folder and editing docker file to accommodate
CTrando Mar 17, 2019
59321d7
#86: decouple scraper from backend
snowme34 Apr 1, 2019
0d19ed8
#86: Allowing the scraper to work with multiple quarters - backend is…
CTrando Apr 3, 2019
279b401
Fixing comment and pruning quarter insert script
CTrando Apr 4, 2019
c9afcc0
Making webreg upload script create database and quarters table for fu…
CTrando Apr 5, 2019
4e9ebc5
Adding necessary config file
CTrando Apr 5, 2019
db0f27e
add quarter parameter to application
snowme34 Apr 8, 2019
922b633
bug fix, add quarter variable, note frontend still not sending the ne…
snowme34 Apr 8, 2019
4cc3bb1
#86 trying to add default quarter support for backend
snowme34 Apr 9, 2019
490ca06
#86 fix import path
snowme34 Apr 9, 2019
e3f76a9
Fixing chrome version
CTrando Apr 15, 2019
47faaba
Merge branch 'scratch/issue86' of github.com:ucsdscheduleplanner/UCSD…
CTrando Apr 15, 2019
682a549
#86 trying to prune Dockerfile
snowme34 Apr 19, 2019
4452996
#86 working on pruning requirements.txt
snowme34 Apr 19, 2019
3c6a080
#86 add note for possible caching bug
snowme34 Apr 19, 2019
9ad923d
#86 disable WI19, no one cares
snowme34 Apr 19, 2019
498ce1e
#86 add mysql non-root user, based on config.ini
snowme34 Apr 19, 2019
29e49a2
Adding golang routes and adding back department functionality and cou…
CTrando Apr 26, 2019
6862d9a
Merge branch 'scratch/issue86' of github.com:ucsdscheduleplanner/UCSD…
CTrando Apr 26, 2019
2872b6a
Adding other github repos, they will not be submodules so will not ac…
CTrando Apr 26, 2019
03b4504
Finished moving backend to Golang
CTrando May 3, 2019
72ca1a6
Adding more tests and working out compatability issues with frontend
CTrando May 3, 2019
db27989
Creating module for Go backend and restructure the code
snowme34 Jun 2, 2019
b771ba5
Add 2 functions in RoutesCommon to remove repeats; Add systematical w…
snowme34 Jun 3, 2019
1531f72
Add development config
snowme34 Jun 3, 2019
0eb55b0
Update RoutesCommon functions and error processing
snowme34 Jun 5, 2019
a7bde26
Cleanup Routes Code and update comments
snowme34 Jun 5, 2019
d8a97fa
Make a straightforward constructor for db struct and update the exist…
snowme34 Jun 6, 2019
fafe144
Add miltiple constructors for db since lower-case struct fields are n…
snowme34 Jun 6, 2019
513216b
Test using mock db
snowme34 Jun 6, 2019
98c989a
refactor, fix error handling
snowme34 Aug 3, 2019
49ddc45
refacotr more
snowme34 Aug 4, 2019
f6af1f6
refactor, restructure, add a ctx package with env
snowme34 Aug 5, 2019
9eb7de2
change embarrassing package name
snowme34 Aug 6, 2019
06feb39
refactor, add handler factoary
snowme34 Aug 11, 2019
3dd064a
remove python code
snowme34 Aug 11, 2019
ddf6944
add Docker support for go backend
snowme34 Aug 19, 2019
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
41 changes: 25 additions & 16 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
FROM joyzoursky/python-chromedriver:3.7
# build
# note the consitency of building and running environments
FROM golang:buster as builder

ENV DEBIAN_FRONTEND noninteractive
WORKDIR /app

# cache mod packages
COPY go.mod .
COPY go.sum .
RUN go mod download

RUN apt-get update
RUN apt-get -y install locales
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
COPY . .

RUN apt-get -y install python3-lxml python3-pip
RUN apt-get -y install default-libmysqlclient-dev
# build stripped binary by default
ARG BUILD_ARGS="-ldflags '-s -w'"
RUN go build -v $BUILD_ARGS -o backend

# ship
FROM debian:buster

WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
RUN pip3 install -r requirements.txt
COPY . /app

ENV PYTHONPATH /app
# to detect if mysql service is up
RUN apt-get -q update && apt-get -qy install netcat
COPY ./wait-for .

# only need config and compiled binary file
COPY ./config ./config
COPY --from=builder /app/backend .

EXPOSE 5000
# handle port exposure in docker compose

CMD ["bash", "./docker-run.sh"]
ENTRYPOINT ["/app/backend"]
14 changes: 0 additions & 14 deletions backend/application.ini

This file was deleted.

53 changes: 0 additions & 53 deletions backend/application.py

This file was deleted.

94 changes: 94 additions & 0 deletions backend/backend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package main

import (
"fmt"
"log"
"net/http"
"path/filepath"
"strconv"

"gopkg.in/ini.v1"

"github.com/ucsdscheduleplanner/UCSD-Schedule-Planner/backend/environ"
"github.com/ucsdscheduleplanner/UCSD-Schedule-Planner/backend/route"
"github.com/ucsdscheduleplanner/UCSD-Schedule-Planner/backend/store"
)

// list of config files to search in order
var configFiles = []string{
filepath.Join(".", "config", "config.ini"),
filepath.Join(".", "config", "config.example.ini"),
}

// Config for the backend
type Config struct {
File *ini.File
Port int
}

// return the first successful read
// return error of last failed
func readConfig() (c *Config, e error) {
for _, f := range configFiles {
if c, e = doReadConfig(f); e == nil {
break
}
}
return
}

func doReadConfig(configFile string) (*Config, error) {

config, err := ini.Load(configFile)

if err != nil {
return nil, fmt.Errorf("Error reading config file: %v", err)
}

if config == nil {
return nil, fmt.Errorf("Could not find config file: %v", configFile)
}

port, err := config.Section("BACKEND").Key("PORT").Int()
if err != nil {
return nil, fmt.Errorf("Error reading port number: %v", err.Error())
}

return &Config{File: config, Port: port}, nil
}

func main() {

config, err := readConfig()

if err != nil {
panic("Failed to load config: " + err.Error())
}

db, err := store.NewDBConfig(config.File)
if err != nil {
panic("Failed to init db: " + err.Error())
}
defer db.Close()

env, err := environ.NewEnvConfig(db, config.File)
if err != nil {
panic("Failed to init env: " + err.Error())
}

log.Printf("Start server on port: %v\n", config.Port)

routeFactory := route.HandlerFactory{Env: env}

http.HandleFunc("/api_course_nums", routeFactory.MakeHandler(route.HandlerCourseNum))
http.HandleFunc("/api_departments", routeFactory.MakeHandler(route.HandlerDepartment))
http.HandleFunc("/api_instructors", routeFactory.MakeHandler(route.HandlerInstructors))
http.HandleFunc("/api_types", routeFactory.MakeHandler(route.HandlerTypes))
http.HandleFunc("/api_class_data", routeFactory.MakeHandler(route.HandlerClassData))

err = http.ListenAndServe(":"+strconv.Itoa(config.Port), nil)

if err != nil {
log.Panic(err) // non-fatal to run deferred calls
}
}
67 changes: 0 additions & 67 deletions backend/backend.py

This file was deleted.

14 changes: 14 additions & 0 deletions backend/config/config.dev.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[BACKEND]
PORT=8080

[DB]
USERNAME=dev
PASSWORD=password
DB_NAME=classes
ENDPOINT=localhost:22180
DEFAULT_QUARTER=SP19

[VARS]
QUARTERS=["SP19"] ; Example: QUARTERS=["SP19", "WI19"]

#sdschedule-database
12 changes: 10 additions & 2 deletions backend/config/config.example.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
[BACKEND]
PORT=8080

[DB]
USERNAME=root
USERNAME=splanner
PASSWORD=password
ENDPOINT=sdschedule-database
DB_NAME=classes
ENDPOINT=
DEFAULT_QUARTER=SP19

[VARS]
QUARTERS=["SP19"] ; Example: QUARTERS=["SP19", "WI19"]
Empty file removed backend/datautil/__init__.py
Empty file.
35 changes: 0 additions & 35 deletions backend/datautil/sql_to_postgres.py

This file was deleted.

Loading