Esempio n. 1
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()
Esempio n. 2
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='')
Esempio n. 3
0
def create_investment(fund_name, amount, date, nav=None, units=None):
    session.add(
        Investment(date=date,
                   fund=fund_name,
                   nav=nav,
                   units=units,
                   amount=amount))
    session.commit()
Esempio n. 4
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()
 def test_insertALotOfIndividual(self):
     """Tests the insertion of a lot of individuals
     """
     session.commit()
     setup_all()
     individuals = [Individual('Ind' + str(i+1)) for i in range(100)]    #TODO: use an higher value
     
     session.commit()
     for ind in individuals: 
         ind.delete()
Esempio n. 6
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!')
Esempio n. 7
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()
Esempio n. 8
0
def update_investment(investment):
    session.add(investment)
    session.commit()
Esempio n. 9
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()
Esempio n. 10
0
#!/usr/bin/env python3
from connection import Base, engine, session
from classPerson import Person
from classAddresses import Addresses
from classAssociation import Association

Base.metadata.bind = engine
Base.metadata.create_all(engine)
session.add(Person())
session.add(Addresses())
session.add(Association())
session.commit()
Association.__table__.drop()
Person.__table__.drop()
Addresses.__table__.drop()
print("Tables dropped")

Base.metadata.create_all(engine)
#Populate user info
user1 = Person(person_name='George',
               person_DOB='1996-6-01',
               active_phone_number='8134441122')
user2 = Person(person_name='Thomas',
               person_DOB='1969-12-4',
               active_phone_number='9921237744')
user3 = Person(person_name='Erik',
               person_DOB='1921-11-09',
               active_phone_number='7771234567')
user4 = Person(person_name='Jack',
               person_DOB='2000-11-25',
               active_phone_number='9002316455')