Exemplo n.º 1
0
def homepage():
    if request.method == 'GET':
        pass
    elif request.method == 'POST':
        long_link = request.form['long_link'].encode('ascii', 'ignore')
        short_link = request.form['short_link'].encode('ascii', 'ignore')
        long_link = str(long_link)
        short_link = str(short_link)
        if session.query(Shortener).filter_by(
                short_link=short_link).scalar() is None:
            if checkURI(long_link):
                session.add(
                    Shortener(short_link=short_link, long_link=long_link))
                session.commit()
            else:
                return "Check the link again"
        else:
            # It already exists in the database
            return "The short name already exists, try something else"
    else:
        pass
    try:
        saved_urls = session.query(Shortener).all()
        return render_template("homepage.html", saved_urls=saved_urls)
    except:
        return render_template("homepage.html", saved_urls='')
Exemplo n.º 2
0
def main():
    URL = 'http://www.nitc.ac.in/app/webroot/img/upload/'
    COURSE = ['BTECH.pdf', 'PG.pdf', 'PhD.pdf']
    session.query(DuesRecord).delete()
    session.commit()
    for course in COURSE:
        if not debug:
            res = requests.get(URL + course)
            dues = open(course, 'wb')
            for chunk in res.iter_content(100000):
                dues.write(chunk)
            dues.close()

        pdf_file_obj = open(course, 'rb')
        pdf_reader = PyPDF2.PdfFileReader(pdf_file_obj)
        total_pages = pdf_reader.numPages

        roll_rex = get_regex(course)

        for i in range(total_pages):
            page = pdf_reader.getPage(i)
            text = page.extractText()
            search_res = roll_rex.findall(text)

            for res in search_res:
                r = res.split('\n')
                roll, name, due = r[0], r[1], r[2]
                try:
                    roll = roll.encode('ascii')
                    name = name.encode('ascii', 'ignore')
                    due = due.encode('ascii')
                except:
                    sys.exit('An error has occurred')
                session.add(DuesRecord(roll_no=roll, name=name, due=int(due)))
        session.commit()
Exemplo n.º 3
0
 def test_getandfilter(self):
     me = Individual('giovanni', population='italians')
     
     me_getby = Individual.get_by(name = 'GIOVANNI')
     assert me_getby == me
     
     me_filterby = session.query(Individual).filter_by(name = 'GIOVANNI')
     assert me_filterby[0] == me
     
     # The only way to do a case-indipendent search is by using .filter:
     me_filter = session.query(Individual).filter(Individual.name.like('giovanni'))
     assert me_filter[0] == me
Exemplo n.º 4
0
def homepageJSON(roll_no):
	roll_no	= roll_no.encode('ascii').upper()
	try:
	    record = session.query(DuesRecord).filter_by(roll_no = roll_no).one()
	    return jsonify(due=record.serialize)          
	except:
	    return '''
            Format: &nbsp&nbsp&nbsp&nbsp hostel-dues.herokuapp.com/&lt;roll_no&gt;''' + '<br>' + '''Example: &nbsp hostel-dues.herokuapp.com/b150487cs'''
Exemplo n.º 5
0
def update_nav():
    investments = session.query(Investment).filter(Investment.nav == None)
    for investment in investments:
        nav = get_nav_on_date(MF_DETAILS[investment.fund]['CODE'],
                              MF_DETAILS[investment.fund]['NAME'],
                              investment.date)
        investment.units = float('%.3f' % (investment.amount / nav))
        investment.nav = float('%.3f' % nav)
    session.commit()
Exemplo n.º 6
0
def homepage():
    name = ''
    due = ''
    result = ''
    if request.method == 'GET':
        return render_template('homepage.html',result = result)
    elif request.method == 'POST':
        roll_no = request.form['roll_no'].encode('ascii').upper()
        try:
            record = session.query(DuesRecord).filter_by(roll_no = roll_no).one()
            name, due = record.name, record.due
            return render_template('homepage.html',name = name, due = due, result = '')        
        except:
            result = "Invalid roll number!"
            return render_template('homepage.html',name = 'NA', due = 0, result = result)        
    else:
        pass 
Exemplo n.º 7
0
def get_doc(name):
    try:
        # doc = docs_collection.find_one({ "name": name });
        doc = session.query(Doc).filter(Doc.name == name).one()
        json_doc = {
            'name': doc.name,
            'body': doc.body,
            'type': doc.type,
        }
        return json_doc

    except NoResultFound:
        raise NoDocFound("Can't find a doc named {}".format(name))

    except MultipleResultsFound:
        raise DatabaseError("Multiple entries to doc {}, something is terribly wrong".format(name))

    return None
Exemplo n.º 8
0
    def save_doc(self, body, name, try_other_names=True, expires=AUTO_CALCULATE_EXPIRY):
        self.expires = expires
        for _ in range(settings.SAVE_RETRIES):
            self.name = name
            self.doc = session.query(Doc).filter(Doc.name == self.name).one_or_none()
            try:
                self.save_or_update_doc(body)

            except DocNotExpired as exception:
                if try_other_names:
                    continue
                else:
                    raise exception

            session.add(self.doc)
            session.commit()
            return self.name

        # If we reach here, the SAVE_RETRIES loop finished and something is bad
        raise FailedToSave('Reached maximum save retry count, seems like many docs exist today!')
Exemplo n.º 9
0
def setup_database():
    """
    If there's no image types, let's setup the database with initial objects
    """
    if session.query(ImageTypes).count() == 0:
        image_type = ImageTypes('Idea')
        session.add(image_type)
        image_type = ImageTypes('Render')
        session.add(image_type)

        page = Pages('Home', True, '/')
        session.add(page)

        page = Pages('Products', False, '/products/')
        session.add(page)

        page = Pages('Services', False, '/services/')
        session.add(page)

        print('OK!')
        session.commit()
Exemplo n.º 10
0
def delete_previous_data():
    session.query(Investment).delete()
Exemplo n.º 11
0
def get_existing_investment(date, fund):
    investment = session.query(Investment).filter(
        Investment.date == date).filter(Investment.fund == fund).first()
    return investment
Exemplo n.º 12
0
def get_last_investment(fund_name):
    last_investment = session.query(Investment).filter(
        Investment.fund == fund_name).order_by(Investment.date.desc()).first()
    return last_investment
Exemplo n.º 13
0
from datetime import date, datetime, timedelta
from classPerson import Person
from connection import session

CONTACTS = session.query(Person)


def printRecord(person):
    # Print record for user.
    print("---------------------------------------")
    print("\n\tName: ", person.person_name)
    print("\tPhone: ", person.active_phone_number)
    print("\n---------------------------------------\n")


def displayResults(records):
    if records.count() > 0:
        for person in records:
            printRecord(person)
    else:
        print("\n No Result found")


def ageSearch():
    minAge = input("\n  Enter Minimum Age: ")
    maxAge = input("  Enter Maximum Age: ")

    # SQL to search by age
    sql = CONTACTS.filter(
        Person.person_DOB.between(
            datetime.now() - timedelta(days=int(maxAge) * 365),
Exemplo n.º 14
0
def delete_doc(name):
    doc = session.query(Doc).filter(Doc.name == name).one_or_none()
    if doc is not None:
        session.delete(doc)
        session.commit()
Exemplo n.º 15
0
def redirectToURL(short_link):
    short_link = short_link.encode('ascii', 'ignore')
    link = session.query(Shortener).filter_by(
        short_link=short_link).first().long_link.encode('ascii')
    return redirect(link)