示例#1
0
    def create(self, sess, comment):
        author = comment.author.name
        q = sess.query(Investor).filter(Investor.name == author).exists()

        if not sess.query(q).scalar():
            sess.add(Investor(name=author))
            comment.reply_wrap(message.modify_create(comment.author, 1000))
示例#2
0
def upload_csv_file():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
        csvf = StringIO(file.read().decode())

        reader = csv.DictReader(csvf, delimiter=',')
        data = [row for row in reader]

        try:
            for row in data:
                organisation = row["Organisation"]
                website = row["Website"]
                sector = row["Sector"]
                fund_currency = row["Fund Currency"]
                fund_size_min = row["Fund Size (Min)"]
                fund_size_max = row["Fund Size (Max)"]
                country = row["Country"]
                type = row["Type"]
                crawl_urls = row["Crawl URLs"]
                description = row["Description"]
                competition_available = row["Competition Available"]

                new_investor = Investor(organisation, website, sector,
                                        fund_currency, fund_size_min,
                                        fund_size_max, country, type,
                                        crawl_urls, description,
                                        competition_available)
                new_investor_id = new_investor.id
                db_session.add(new_investor)
                db_session.commit()
        except:
            raise
            return """
                <html>
                <head><title>Wrong format of CSV file</title></head>
                <body>
                Insertion failed because the CSV file is wrongly formatted. The CSV file should contain the following columns:
                  "Organisation",
                  "Website",
                  "Sector",
                  "Fund Currency",
                  "Fund Size (Min)",
                  "Fund Size (Max)",
                  "Country",
                  "Type",
                  "Crawl URLs",
                  "Description",
                  "Competition Available".
                </body>
                </html>
                """

        return redirect("/")
示例#3
0
    def create(self, sess, comment):
        author = comment.author.name
        q = sess.query(Investor).filter(Investor.name == author).exists()

        # Let user know they already have an account
        if sess.query(q).scalar():
            comment.reply_wrap(message.create_exists_org)
            return

        # Create new investor account
        sess.add(Investor(name=author))
        comment.reply_wrap(message.modify_create(comment.author, 1000))
示例#4
0
 def test_deleted(self):
     investor, _, submission = self.create_investment(100, iid="3")
     submission.removed = True
     investor = Investor(name=submission.author.name)
     sess = self.session
     sess.add(investor)
     sess.commit()
     self.buyabler.main()
     investor = sess.query(Investor).filter(
         Investor.name == submission.author.name).one()
     self.assertTrue(investor.balance == config.STARTING_BALANCE)
     with self.assertRaises(NoResultFound):
         sess.query(Buyable).filter(Buyable.post == submission.id).one()
示例#5
0
def main():
    engine = create_engine(config.DB, pool_recycle=60, pool_pre_ping=True)
    session_maker = scoped_session(sessionmaker(bind=engine))
    sess = session_maker()

    users = []
    with open(sys.argv[1], 'r') as r:
        users = [x.replace('\n', '') for x in r.readlines()]

    counter = 0
    for user in users:
        sess.add(Investor(name=user))
        print(f"{counter}. Added {user}")
        counter += 1
    sess.commit()
    def create(self, sess, comment):
        """
        This one is responsible for creating a new user
        """
        author = comment.author.name
        user_exists = sess.query(Investor).filter(Investor.name == author).exists()

        # Let user know they already have an account
        if sess.query(user_exists).scalar():
            return comment.reply_wrap(message.CREATE_EXISTS_ORG)

        # Create new investor account
        sess.add(Investor(name=author))
        # TODO: Make the initial balance a constant
        return comment.reply_wrap(message.modify_create(comment.author, config.STARTING_BALANCE))
示例#7
0
 def test_base(self):
     investor, buyable, submission = self.create_investment(1000, iid="1")
     submission.link_flair_text = "OC"
     investor = Investor(name=submission.author.name)
     sess = self.session
     sess.add(investor)
     sess.commit()
     self.buyabler.main()
     investor = sess.query(Investor).filter(
         Investor.name == submission.author.name).one()
     self.assertTrue(investor.balance != config.STARTING_BALANCE)
     buyable = sess.query(Buyable).filter(
         Buyable.post == submission.id).one()
     self.assertTrue(buyable.done)
     self.assertTrue(buyable.oc)
     self.assertTrue(buyable.profit > 0)
示例#8
0
 def test_deleted(self):
     investor, _, submission = self.create_investment(100, iid='3')
     submission.deleted = True
     investor = Investor(name=submission.author.name)
     sess = self.session
     sess.add(investor)
     sess.commit()
     self.buyabler.main()
     investor = sess.query(Investor).\
         filter(Investor.name == submission.author.name).\
         one()
     self.assertTrue(investor.balance == config.STARTING_BALANCE)
     buyable = sess.query(Buyable).\
         filter(Buyable.post == submission.id).\
         one()
     self.assertTrue(buyable.done)
     self.assertEqual(buyable.profit, 0)
示例#9
0
def store_info(request):
    new_username = request.POST['uesrname']
    new_password = request.POST['password']
    new_mobile = request.POST['mobile']
    request.session['uesrname'] = new_username
    request.session['mobile'] = new_mobile
    try:
        new_user = Investor(username=new_username, password=hashed_password(new_password), mobile=new_mobile,realname='_', idtype = 0, idno='_', email='_', openid =request.session['openid'], taid='_',education='_',occupation='_',point='_',address='_',appendage='_')
    except:
        new_user = Investor(username=new_username, password=hashed_password(new_password), mobile=new_mobile,realname='_', idtype = 0, idno='_', email='_', openid ='_', taid='_',education='_',occupation='_',point='_',address='_',appendage='_')
    new_user.save()
    request.session['userID'] = new_user.id
    return JsonResponse({})
示例#10
0
def add_investor():
    if request.method == "POST":
        organisation = request.form["organisation"]
        website = request.form["website"]
        sector = request.form["sector"]
        fund_currency = request.form["fund_currency"]
        fund_size_min = request.form["fund_size_min"]
        fund_size_max = request.form["fund_size_max"]
        country = request.form["country"]
        type = request.form["type"]
        crawl_urls = request.form["crawl_urls"]
        description = request.form["description"]
        competition_available = request.form["competition_available"]

        new_investor = Investor(organisation, website, sector, fund_currency,
                                fund_size_min, fund_size_max, country, type,
                                crawl_urls, description, competition_available)
        new_investor_id = new_investor.id
        db_session.add(new_investor)
        db_session.commit()

        data = {
            "id": new_investor_id,
            "organisation": organisation,
            "website": website,
            "sector": sector,
            "fund_currency": fund_currency,
            "fund_size_min": fund_size_min,
            "fund_size_max": fund_size_max,
            "country": country,
            "type": type,
            "crawl_urls": crawl_urls,
            "description": description,
            "competition_available": competition_available
        }

        pusher_client.trigger('table', 'new-record', {'data': data})

        return redirect("/add_investor", code=302)
    else:
        investors = Investor.query.all()
        return render_template('add_investor.html', investors=investors)
示例#11
0
 def create_investment(self, amount, start_upvotes, end_upvotes, iid='0'):
     investor = Investor(name='investor' + iid)
     submission = Submission('sid' + iid)
     comment = Comment('cid' + iid, investor.name, 'dummy', submission)
     self.reddit.add_submission(submission)
     investment = Investment(
         post=comment.submission.id,
         upvotes=start_upvotes,
         comment=comment.id,
         name=comment.author.name,
         amount=amount,
         response="0",
         done=False,
     )
     investment.time = int(time.time()) - config.INVESTMENT_DURATION - 1
     submission.ups = end_upvotes
     sess = self.Session()
     sess.add(investor)
     sess.add(investment)
     sess.commit()
     return investor, investment
示例#12
0
 def create_investment(self, amount, iid="0"):
     investor = Investor(name="investor" + iid)
     submission = Submission("sid" + iid)
     comment = Comment("cid" + iid, investor.name, "dummy", submission)
     self.reddit.add_submission(submission)
     investment = Investment(
         post=comment.submission.id,
         upvotes=1,
         comment=comment.id,
         name=comment.author.name,
         amount=amount,
         response="0",
         done=False,
     )
     buyable = Buyable(post=submission.id,
                       name=submission.author.name,
                       response="brid" + iid)
     buyable.time = int(time.time()) - config.INVESTMENT_DURATION - 1
     sess = self.session
     sess.add(buyable)
     sess.add(investor)
     sess.add(investment)
     sess.commit()
     return investor, buyable, submission
示例#13
0
 def add_investor(self):
     print("-" * 30)
     name = input("Enter name:  ")
     print("-" * 30)
     self.investors.append(Investor(name))
     print(f"Investor {name} was successfully created")