from flask import request
from server.api import token_required
from flask_restplus import Resource, fields
from server.app import api, db
from server.models.Availabilities import Availabilities
from server.models.Timezones import Timezones
from server.models.Users import Users

NS = api.namespace('availabilities',
                   description='Endpoint for adding a new availability.')

success = api.model('Success', {
    'message': fields.String,
    'success': fields.Boolean
})

availability = api.model('Availability', {
    'id': fields.Integer,
    'user_id': fields.Integer,
    'day_of_week': fields.Integer,
    'from_time': fields.Integer,
    'to_time': fields.Integer
})

all_availabilities = api.model('availabilities', {
    'availabilities': fields.List(fields.Nested(availability))
})

form = api.model('availability form', {
    'user_id': fields.Integer,
    'day_of_week': fields.Integer,
Exemple #2
0
Return success message
'''
from flask import request
from flask_restplus import Resource, fields
from server.api import token_required
from server.app import api, db
from server.models.Users import Users
from server.models.LanguagesKnown import LanguagesKnown
from server.models.LanguagesWanted import LanguagesWanted
from server.models.Languages import Languages

#input form
update_form = api.model(
    'Update form', {
        'user_name': fields.String,
        'email': fields.String,
        'pref_timezone': fields.String,
        'native_language': fields.String,
        'wanted_language': fields.String
    })

#output form
status = api.model('Status', {
    'message': fields.String,
})

NS = api.namespace('update_user', description='Update a user\'s information')


@NS.route('')
class UpdateUser(Resource):
    #What you post
Exemple #3
0
from flask import Flask, request, send_file, request
from flask_restx import Resource, Api, fields, reqparse
from datetime import datetime, timedelta

from server.app import api, app
from server.services.UnswScraper import UnswScraper
from server.services import SupportedPortals
from server.config import scraper_token_key

from server.models import db_session
from server.models.User import User

login_model = api.model('Login_Model', {
    'username': fields.String,
    'password': fields.String,
    'uni': fields.String,
},
                        required=True)


@api.route('/jobs/login')
class LoginRoute(Resource):
    @api.expect(login_model, validate=True)
    @api.doc(description='''
    Attempts to log into to portal with provided credentials. If successful, 
    then we upsert the user info (not password), and portal cookie into database. 
    We then return a jwt token to maintain user session on our application.
    ''')
    def post(self):
        login = request.get_json()
        username, password, uni = login.values()
Exemple #4
0
from server.app import api, db
from server.models.Requests import Requests
from server.api import get_token, token_required, verify_request
from server.models.Requests import Requests
from server.models.Users import Users
from server.api.get_user import USER_MODEL
from server.helpers.user import get_user
from server.app import mdb
import datetime

NS = api.namespace(
    'request', description="Make a request to chat with someone")

request_form = api.model('Request form', {
    'partner_id': fields.Integer,
    'date': fields.String,
    'from_time': fields.Integer,
    'to_time': fields.Integer
})

success_resp = api.model('Successful request', {
    'id': fields.String
})


GET_REQUEST_RESPONSE = api.model('Get request response', {
    'request_id': fields.Integer,
    'other_user': fields.Nested(USER_MODEL),
    'from_time': fields.String,
    'to_time': fields.String,
    'req_accepted': fields.Boolean,
    'req_confirmed': fields.Boolean
Exemple #5
0
from server.models.Users import Users
from server.models.LanguagesKnown import LanguagesKnown
from server.models.LanguagesWanted import LanguagesWanted
from server.models.Languages import Languages
from server.app import mdb

NS = api.namespace('register',
                   description='Endpoint for registering a new user.')

token = api.model('Token', {
    'token': fields.String,
    'user_id': fields.Integer,
    'user_name': fields.String,
    'email': fields.String,
    'pref_timezone': fields.String,
    'learning_id': fields.Integer,
    'learning_language': fields.String,
    'native_id': fields.Integer,
    'native_language': fields.String,
    'message': fields.String,
    'authenticated': fields.Boolean
})

form_input = api.model('Register form', {
    'user_name': fields.String,
    'email': fields.String,
    'password': fields.String,
    'pref_timezone': fields.String,
    'native_language': fields.Integer,
    'pref_language': fields.Integer
})
import pickle

from flask import Flask, request, send_file, request
from flask_restx import Resource, Api, fields, reqparse

from server.app import api, app, token_parser
from server.config import scraper_token_key
from server.services.UnswScraper import UnswScraper
from server.models import db_session
from server.models.User import User
from server.models.Search import Search
from server.utils import authentication
from server.services import SupportedPortals

job_detail_model = api.model('Job_Detail_Model', {
  'link': fields.String,
}, required=True)

@api.route('/jobs/detail')
class JobDetail(Resource):
  @api.expect(token_parser, job_detail_model, validate=True)
  @api.doc(description='''
    Scrape portal for extra details of a particular job listing using the link
    provided by user in the request payload. 
    ''')
  @api.response(400, 'Invalid input or error processing data encountered.')
  @api.response(404, 'Error connecting to data source.')
  @api.response(200, 'Data sucessfully processed and returned.')
  def post(self):
    link = request.get_json().get('link')
    token = token_parser.parse_args().get('token')
Exemple #7
0
# coding=utf-8

from flask_restplus import fields
from server.status import FeedAPIStatus
from server.app import api

response_success = api.response(
    200, '成功',
    api.model(
        'response_success', {
            'state':
            fields.Integer(description=str(FeedAPIStatus.Ok)),
            'msg':
            fields.String(
                description=FeedAPIStatus.Decriptions[FeedAPIStatus.Ok]),
        }))

response_bad_request = api.response(
    400, '请求参数错误',
    api.model(
        'response_bad_request', {
            'state':
            fields.Integer(description=str(FeedAPIStatus.BadRequest)),
            'msg':
            fields.String(description=FeedAPIStatus.Decriptions[
                FeedAPIStatus.BadRequest]),
        }))

response_unauthorized = api.response(
    401, '验证失败',
    api.model(
Exemple #8
0
from flask_restplus import Resource, fields
from server.app import api, db
from server.models.Availabilities import Availabilities
from server.models.Users import Users
from server.models.Timezones import Timezones
from server.api import token_required

NS = api.namespace(
    "search_availabilities",
    description="Query for availabilities that overlap with the request")

availabilities = api.model(
    'availability', {
        'id': fields.String,
        'user_id': fields.Integer,
        'user_name': fields.String,
        'day_of_week': fields.Integer,
        'from_time': fields.Integer,
        'to_time': fields.Integer
    })

response = api.model(
    'availabilities',
    {'availabilities': fields.List(fields.Nested(availabilities))})


@NS.route("")
class SearchAvailabilities(Resource):
    '''Contains post method for logging in'''
    @api.marshal_with(response)
    @token_required
from flask import request
from flask_restplus import Resource, fields
from server.app import api, db
from server.models.Requests import Requests
from server.api import get_token, token_required
from server.app import mdb
from bson import ObjectId

request_form = api.model('Accept request model', {
  'request_id': fields.String
})

accept_response = api.model('Accept request response', {
  'message': fields.String
})

NS = api.namespace('accept_request', description='Accept a chat request')

@NS.route('')
class AcceptRequest(Resource):
  #What you post
  @NS.expect(request_form)
  #What you return
  @NS.marshal_with(accept_response)
  #Checking if the user is registered
  @token_required
  def post(self, cur_user):
    # If cur_user is not authenticated, decorator return to the client without entering this function
    accept_request = request.get_json()
    if accept_request == None:
      accept_request = request.form
Exemple #10
0
from flask_restplus import Resource, fields
from server.api import token_required, verify_request
from server.app import api, db
from server.models.Requests import Requests
from server.models.Users import Users
from pprint import pprint
from bson import ObjectId

NS = api.namespace('notifications',
                   description='View notifications')

READ_PATCH_FORM = {
    'id': fields.String  # ID of notification to mark as read
}

READ_PATCH_MODEL = api.model('Read notification model', READ_PATCH_FORM)


def mongo_encode(doc):
  enc_doc = {}
  for key in doc:
    if isinstance(doc[key], ObjectId):
      enc_doc[key] = str(doc[key])
    else:
      enc_doc[key] = doc[key]
  return enc_doc


@NS.route('')
class Notifications(Resource):
  @token_required
from flask import Flask, send_file, request, make_response
from flask_restx import Resource, Api, fields

from server.app import api, app, token_parser
from server.services.calendarMake import generateCalendarSummarized
from server.utils import convertJobsFromListDicts, authentication
from server.services import SupportedPortals

jobs_model = api.model('Jobs_Model', {
    'jobs':
    fields.List(
        fields.Raw(description='''
      title: string,
      company: string.
      link: string,
      summary: string.
      reminder_date: string (datetime),
      location: string
    '''))
},
                       required=True)


@api.route('/jobs/calendar')
class CalendarRoute(Resource):
    @api.expect(token_parser, jobs_model, validate=True)
    @api.doc(description='''
    Generates a calendar file from given list of jobs after processing, then
    sends back an ics file.
    ''')
Exemple #12
0
from flask import Flask, request, send_file, request
from flask_restx import Resource, Api, fields, reqparse

from server.app import api, app, token_parser
from server.config import scraper_token_key
from server.services.UnswScraper import UnswScraper
from server.models import db_session
from server.models.User import User
from server.models.Search import Search
from server.utils import authentication
from server.services import SupportedPortals

search_model = api.model('Search_Model', {
    'keywords': fields.String,
    'location': fields.String,
},
                         required=True)


@api.route('/jobs')
class ScrapeRoute(Resource):
    @api.expect(token_parser, search_model, validate=True)
    @api.doc(description='''
    Scrape portal for job listings using provided search terms and a cookie 
    previously stored in the db. Search terms will then be stored in the db 
    then return the resulting list of jobs.
    ''')
    @api.response(400, 'Invalid input or error processing data encountered.')
    @api.response(404, 'Error connecting to data source.')
    @api.response(200, 'Data sucessfully processed and returned.')
Exemple #13
0
who have the same timezone
and language.

Return a list of users, and count
'''
from flask import request
from flask_restplus import Resource, fields
from server.app import api, db
from server.models.Users import Users
from server.api import token_required

NS = api.namespace(
    "search_timezone", description="Query for users with same preferred timezone")

username = api.model('username', {
    'username': fields.String
})

response = api.model('Users', {
    'usernames': fields.List(fields.Nested(username))
})

@NS.route("")
class SearchTimezone(Resource):
  '''Contains post method for logging in'''

  @api.marshal_with(response)
  @token_required
  def get(self, curr_user):

    users = Users.query.filter_by(pref_timezone=curr_user.pref_timezone).all()
Exemple #14
0
from flask import request
from flask_restplus import Resource, fields
from server.app import api, db
from server.models.Users import Users
from server.api import token_required

NS = api.namespace('get_user', description='Get user info')

USER_MODEL = api.model('User model', {
    'id': fields.Integer,
    'user_name': fields.String,
    'email': fields.String,
    'pref_timezone': fields.String,
    'learning_id': fields.Integer,
    'learning_language': fields.String,
    'native_id': fields.Integer,
    'native_language': fields.String
})


@NS.route('')
class GetUser(Resource):
  @NS.marshal_with(USER_MODEL)
  @token_required
  def get(self, user):
    resp = {
        'id': user.id,
        'user_name': user.user_name,
        'email': user.email,
        'pref_timezone': user.pref_timezone
    }
Exemple #15
0
'''
GET language id mapped to language name
'''

from flask import request
from flask_restplus import Resource, fields
from server.api import token_required
from server.models.Timezones import Timezones
from server.app import api

timezone = api.model(
    'Timezone', {
        'id': fields.Integer,
        'timezone_name': fields.String,
        'timezone_offset': fields.Integer
    })

NS = api.namespace(
    'get_timezones',
    description="Get a list of available timezones in Talktime.")


@NS.route('')
class GetTimezones(Resource):
    @NS.marshal_list_with(timezone)
    def get(self):
        return [t.to_dict() for t in Timezones.query.all()]
Exemple #16
0
Get route to get all of the opening requests for the user
Return success message
'''
from flask import request
from flask_restplus import Resource, fields
from server.api import token_required
from server.app import api, db
from server.models.Requests import Requests
from server.app import mdb

#output form
opening_request = api.model(
    'Opening Request', {
        'other_user_id': fields.String,
        'other_user_name': fields.String,
        'from_time': fields.Integer,
        'to_time': fields.Integer,
        'req_accepted': fields.Boolean,
        'req_confirmed': fields.Boolean
    })

NS = api.namespace('get_opening_request',
                   description='Get all opening requests of a user')


@NS.route('')
class GetOpeningRequest(Resource):
    # @NS.marshal_list_with(opening_request)
    @token_required
    def get(self, cur_user):
        # Search the request table and return all opening requests (confirmed = false, acceptd = false)
'''
GET language id mapped to language name
'''

from flask import request
from flask_restplus import Resource, fields
from server.api import token_required
from server.models.Languages import Languages
from server.app import api

language = api.model('Language', {
    'id': fields.Integer,
    'language_name': fields.String
})

NS = api.namespace(
    'get_languages',
    description="Get a list of available languages to use on Talktime.")


@NS.route('')
class GetLanguages(Resource):
    @NS.marshal_list_with(language)
    def get(self):
        return [l.to_dict() for l in Languages.query.all()]