def stock_crypto(): if not g.user: flash("Access unauthorized.", "error") return redirect("/") form = TickerForm() user = g.user if form.validate_on_submit(): symbol = form.ticker.data region = form.region.data data = search_stock(symbol, region) if data["type"] == "stock": if Stock.query.filter_by(ticker_symbol=symbol).first(): stock = Stock.query.filter_by(ticker_symbol=symbol).first() return render_template('stock-profile.html', data=data, user=user, stock_data=data, stock=stock) else: stock = Stock(stock_name=data["name"], ticker_symbol=data["symbol"], region=region, which_type=data["type"], stock_price=data["price"]) db.session.add(stock) db.session.commit() return render_template('stock-profile.html', data=data, user=user, stock_data=data, stock=stock) elif data["type"] == "crypto": if Cryptocurrency.query.filter_by(ticker_symbol=symbol).first(): crypto = Cryptocurrency.query.filter_by( ticker_symbol=symbol).first() return render_template('stock-profile.html', data=data, user=user, crypto_data=data, crypto=crypto) else: crypto = Cryptocurrency(crypto_name=data["name"], ticker_symbol=data["symbol"], region=region, which_type=data["type"], crypto_price=data["price"]) db.session.add(crypto) db.session.commit() return render_template('stock-profile.html', data=data, user=user, crypto_data=data, crypto=crypto) elif data["type"] == "not found": flash( "Please insert correct ticker symbol for stocks and cryptocurrencies only!", "error") return redirect(f'/users/{user.username}') else: return redirect(f'/users/{user.username}')
def user_page(username): if not g.user: flash("Access unauthorized.", "error") return redirect("/") else: user = User.query.get(username) form = TickerForm() [stocks, cryptos] = popular_ticker() return render_template('userpage.html', user=user, stocks=stocks, cryptos=cryptos, form=form)
def index(): script = None div = None show_form = True form = TickerForm() if form.validate_on_submit(): ticker = form.ticker_symbol.data #flash('You entered: %s' % (company)) dates = get_dates() sdata = get_stock_data(ticker, dates[0], dates[1]) #if sdata.empty: # bad_result = 'Data for {} not found'.format(company) #else: values = [form.closing_price.data, form.adj_close.data, form.opening_price.data, form.adj_opening.data] print(values) script, div = plot_stocks(sdata, ticker, values) show_form = False #script, div = plot_stocks(get_stock_data('AAPL','2017-09-06','2017-10-06'), 'AAPL') return render_template('index.html', form = form,script=script, div=div, show_form = show_form)
def ticker_detail(request, ticker_symbol): try: ticker = Ticker.objects.get(ticker_symbol=ticker_symbol) except: # if the ticker isn't found, redirect to the listing of all tickers return redirect('ticker_overview') if request.POST: form = TickerForm(request.POST, instance=ticker) if form.is_valid(): model_instance = form.save(commit=True) form = TickerForm(instance=ticker) context = { 'title_value': '%s (%s)' % (ticker.company_name, ticker.ticker_symbol), 'form': form, 'ticker':ticker } return render(request, 'satellite/ticker_detail.html', context)
def network_ace_match(request): from atrinsic.util.AceApi import search_company, create_company from atrinsic.base.models import Organization from forms import TickerForm if request.POST: currentOrg = request.POST['currentOrg'] useOrg = request.POST['company'] org = Organization.objects.get(id=currentOrg) if useOrg == '0': create_company(org) else: org.ace_id = useOrg org.save() if org.org_type == 1: form = TickerForm(initial={ 'ticker': org.ticker, }) return HttpResponseRedirect('/network/') else: return HttpResponseRedirect( '/network/account/advertiser/applications/')
def coverage_detail(request, ticker_symbol): try: ticker = Ticker.objects.get(ticker_symbol=ticker_symbol) except: # if the ticker isn't found, redirect to the listing of all tickers return redirect('coverage_index') services_to_filter_by = None service_filter_description = None tickers_to_filter_by = None single_authors = get_authors_from_article_set() form = TickerForm(instance=ticker) if request.POST: form = TickerForm(request.POST, instance=ticker) if form.is_valid(): model_instance = form.save(commit=True) if 'coverage' in request.POST: # delete records that are already there coverage_type_objects = CoverageType.objects.filter(ticker=ticker) print 'deleting existing CoverageType records for %s (%d)' % (ticker.ticker_symbol, len(coverage_type_objects)) coverage_type_objects.delete() # replace them with the records passed along in POST # we expect the keys per selection to have this format: "cid_x__sid_y", where x is a content choice integer value, y is a service id selected_keys = [k for k in request.POST if k.startswith('author_')] for k in selected_keys: k = k.replace('author_','') print k, '---------------' choice_id, service_id = k.replace("cid_","").replace("sid_","").split('__') ct = CoverageType() ct.coverage_type = int(choice_id) ct.ticker = ticker ct.service = Service.objects.get(id=service_id) author_key = 'author_'+k print author_key if author_key in request.POST: ct.author = request.POST[author_key] ct.save() print 'added CoverageType record: %s %s %d %s' % (ct.service.pretty_name, ct.ticker.ticker_symbol, ct.coverage_type, ct.author) else: pass else: pass services = Service.objects.all() today = datetime.now() date_today = today.date() ninety_days_ago = (date_today - timedelta(days=90)) articles = [a for a in Article.objects.filter(ticker=ticker).exclude(tags=None).exclude(tags='') if a.date_pub is not None and a.date_pub.date() >= ninety_days_ago] relevant_articles = set() ten_percent_promises = set() everlasting = set() analysis = set() featured = set() earnings = set() mission_log = set() buy_recommendations = set() five_and_three = set() best_buys_now = set() two_minute_drills = set() commentary = set() news = set() for a in articles: if '10 promise' in a.tags: ten_percent_promises.add(a) if 'everlasting' in a.tags: everlasting.add(a) if 'analysis' in a.tags: analysis.add(a) if 'featured' in a.tags: featured.add(a) if 'earnings' in a.tags: earnings.add(a) if 'mission_log' in a.tags: mission_log.add(a) if 'buy recommendation' in a.tags: buy_recommendations.add(a) if '5 and 3' in a.tags: five_and_three.add(a) if 'best buys now' in a.tags: best_buys_now.add(a) if '2 minute drill' in a.tags: two_minute_drills.add(a) if 'commentary' in a.tags: commentary.add(a) if 'news' in a.tags: news.add(a) dictionary_of_values = { 'ticker': ticker, 'form': form, 'coverage_type_choices': COVERAGE_CHOICES, 'services': services, 'single_authors': single_authors, 'title_value': '%s (%s)' % (ticker.company_name, ticker.ticker_symbol), 'relevant_articles': relevant_articles, 'ten_percent_promises': ten_percent_promises, 'everlasting': everlasting, 'featured': featured, 'earnings': earnings, 'mission_log': mission_log, 'buy_recommendations': buy_recommendations, 'five_and_three': five_and_three, 'best_buys_now': best_buys_now, 'two_minute_drills': two_minute_drills, 'commentary': commentary, 'news': news, } return render(request, 'satellite/coverage_detail.html', dictionary_of_values)
def network_account_publisher_applications_approve(request, id=None): ''' View to allow Network Admins the ability to approve a publisher Application ''' from atrinsic.base.models import Organization,OrganizationContacts from django.core.mail import EmailMultiAlternatives from forms import TickerForm publisher = get_object_or_404(Organization, id=id) no_email_sent = False if publisher.status != ORGSTATUS_LIVE: try: pubContact = OrganizationContacts.objects.get(email__isnull=False, organization=publisher) subject, from_email, to = 'Atrinsic Affiliate Network Publisher Application Status', '*****@*****.**', pubContact.email text_content = """ Dear """ + pubContact.firstname + ' ' + pubContact.lastname + """, Congratulations! Your application to the Atrinsic Affiliate Network has been approved. You may now login to the Atrinsic Affiliate Network http://network.atrinsic.com/accounts/login/ with your username and password created at the time of sign up. Your username is your email address used at time of sign-up. If you have forgotten your login password, please visit our login page to reset the password for your account. You may reset your password at any time by visiting "Settings" and updating your individual password in the "Users" section of the interface. When you are ready, just follow the three easy steps below: 1. Join Programs Visit "Manage Advertisers" and "Find New Advertisers" to location programs that interest you. Apply for any and all programs that you would like to join. Advertisers will notify you with approval via email. 2. Create Links Once you are approved to partner with Advertiser, log in to your account again. Find the merchant on the "Manage Advertisers" section of the interface. Select "Get Links" and then, the type of link you would like to place on your website, and copy and paste the appropriate code directly into your site. 3. Run Reports Once Advertiser links are placed in your website, you can login to check your reports at any time to see how your links are performing. Choose to partner with Advertisers who offer products and services that are most likely to be of interest to your visitors. Once you have chosen appropriate Advertisers, you can increase the likelihood of purchase from your site by placing product, text, banners, product links and content on your site to provide more relevance for visitors. Use our reports to evaluate your successes, so that you can focus on making all your partnerships work. Please contact us at [email protected] with any questions as they may arise. We look forward to a long and successful partnership with you! Warm Regards, The Atrinsic Affiliate Network Publisher Team [email protected] """ html_content = """ Dear """ + pubContact.firstname + ' ' + pubContact.lastname + """,<br> <br> Congratulations! Your application to the Atrinsic Affiliate Network has been approved.<br> <br> You may now <a href="http://network.atrinsic.com/accounts/login/">login to the Atrinsic Affiliate Network</a> with your username and password created at the time of sign up. Your username is your email address used at time of sign-up. If you have forgotten your login password, please visit our login page to reset the password for your account.<br> <br> You may reset your password at any time by visiting "Settings" and updating your individual password in the "Users" section of the interface.<br> <br> When you are ready, just follow the three easy steps below:<br> <br> 1. Join Programs<br> Visit "Manage Advertisers" and "Find New Advertisers" to location programs that interest you. Apply for any and all programs that you would like to join. Advertisers will notify you with approval via email.<br> <br> 2. Create Links<br> Once you are approved to partner with Advertiser, log in to your account again. Find the merchant on the "Manage Advertisers" section of the interface. Select "Get Links" and then, the type of link you would like to place on your website, and copy and paste the appropriate code directly into your site.<br> <br> 3. Run Reports<br> Once Advertiser links are placed in your website, you can login to check your reports at any time to see how your links are performing.<br> <br> Choose to partner with Advertisers who offer products and services that are most likely to be of interest to your visitors. Once you have chosen appropriate Advertisers, you can increase the likelihood of purchase from your site by placing product, text, banners, product links and content on your site to provide more relevance for visitors. Use our reports to evaluate your successes, so that you can focus on making all your partnerships work.<br> <br> Please contact us at <a href="mailto:[email protected]">[email protected]</a> with any questions as they may arise.<br> <br> We look forward to a long and successful partnership with you!<br> <br> <br> Warm Regards,<br> <br> The Atrinsic Affiliate Network Publisher Team<br> <a href="mailto:[email protected]">[email protected]</a>""" msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) msg.attach_alternative(html_content, "text/html") msg.send() except: no_email_sent = True #create_company(publisher) publisher.status = ORGSTATUS_LIVE publisher.date_joined = datetime.datetime.now() publisher.save() #ACE INSERT IF NO MATCHES ARE FOUND matches = search_company(publisher.company_name) if len(matches) > 0: if request.method == 'POST': form = TickerForm(request.POST) if form.is_valid(): publisher.ticker = form.cleaned_data['ticker'] publisher.save() #redirect to new url and template to display list. Chose or create if no_email_sent == True: error_msg = 'An error occured when trying to contact the publisher automaticly to advise him of the approval. Please attempt this manualy. This is likely cause by the publisher not entering valid contact info.' else: error_msg = '' return AQ_render_to_response(request, 'network/search-ace.html', { 'matches':matches, 'orgId':publisher.id, 'error':error_msg, }, context_instance=RequestContext(request)) else: create_company(publisher) if request.method == 'POST': form = TickerForm(request.POST) if form.is_valid(): publisher.ticker = form.cleaned_data['ticker'] publisher.save() return HttpResponseRedirect('/network/account/publisher/applications/') else: form = TickerForm(initial={ 'ticker' : publisher.ticker, }) if no_email_sent == True: return AQ_render_to_response(request, 'network/publisher-applications-deny.html', { 'publisher' : publisher, 'error':'An error occured when trying to contact the publisher automaticly to advise him of the approval. Please attempt this manualy. This is likely cause by the publisher not entering valid contact info.', }, context_instance=RequestContext(request)) else: return AQ_render_to_response(request, 'network/publisher-applications-approve.html', { 'publisher' : publisher, 'form' : form, }, context_instance=RequestContext(request))
def network_account_publisher_applications_approve(request, id=None): ''' View to allow Network Admins the ability to approve a publisher Application ''' from atrinsic.base.models import Organization, OrganizationContacts from django.core.mail import EmailMultiAlternatives from forms import TickerForm publisher = get_object_or_404(Organization, id=id) no_email_sent = False if publisher.status != ORGSTATUS_LIVE: try: pubContact = OrganizationContacts.objects.get( email__isnull=False, organization=publisher) subject, from_email, to = 'Atrinsic Affiliate Network Publisher Application Status', '*****@*****.**', pubContact.email text_content = """ Dear """ + pubContact.firstname + ' ' + pubContact.lastname + """, Congratulations! Your application to the Atrinsic Affiliate Network has been approved. You may now login to the Atrinsic Affiliate Network http://network.atrinsic.com/accounts/login/ with your username and password created at the time of sign up. Your username is your email address used at time of sign-up. If you have forgotten your login password, please visit our login page to reset the password for your account. You may reset your password at any time by visiting "Settings" and updating your individual password in the "Users" section of the interface. When you are ready, just follow the three easy steps below: 1. Join Programs Visit "Manage Advertisers" and "Find New Advertisers" to location programs that interest you. Apply for any and all programs that you would like to join. Advertisers will notify you with approval via email. 2. Create Links Once you are approved to partner with Advertiser, log in to your account again. Find the merchant on the "Manage Advertisers" section of the interface. Select "Get Links" and then, the type of link you would like to place on your website, and copy and paste the appropriate code directly into your site. 3. Run Reports Once Advertiser links are placed in your website, you can login to check your reports at any time to see how your links are performing. Choose to partner with Advertisers who offer products and services that are most likely to be of interest to your visitors. Once you have chosen appropriate Advertisers, you can increase the likelihood of purchase from your site by placing product, text, banners, product links and content on your site to provide more relevance for visitors. Use our reports to evaluate your successes, so that you can focus on making all your partnerships work. Please contact us at [email protected] with any questions as they may arise. We look forward to a long and successful partnership with you! Warm Regards, The Atrinsic Affiliate Network Publisher Team [email protected] """ html_content = """ Dear """ + pubContact.firstname + ' ' + pubContact.lastname + """,<br> <br> Congratulations! Your application to the Atrinsic Affiliate Network has been approved.<br> <br> You may now <a href="http://network.atrinsic.com/accounts/login/">login to the Atrinsic Affiliate Network</a> with your username and password created at the time of sign up. Your username is your email address used at time of sign-up. If you have forgotten your login password, please visit our login page to reset the password for your account.<br> <br> You may reset your password at any time by visiting "Settings" and updating your individual password in the "Users" section of the interface.<br> <br> When you are ready, just follow the three easy steps below:<br> <br> 1. Join Programs<br> Visit "Manage Advertisers" and "Find New Advertisers" to location programs that interest you. Apply for any and all programs that you would like to join. Advertisers will notify you with approval via email.<br> <br> 2. Create Links<br> Once you are approved to partner with Advertiser, log in to your account again. Find the merchant on the "Manage Advertisers" section of the interface. Select "Get Links" and then, the type of link you would like to place on your website, and copy and paste the appropriate code directly into your site.<br> <br> 3. Run Reports<br> Once Advertiser links are placed in your website, you can login to check your reports at any time to see how your links are performing.<br> <br> Choose to partner with Advertisers who offer products and services that are most likely to be of interest to your visitors. Once you have chosen appropriate Advertisers, you can increase the likelihood of purchase from your site by placing product, text, banners, product links and content on your site to provide more relevance for visitors. Use our reports to evaluate your successes, so that you can focus on making all your partnerships work.<br> <br> Please contact us at <a href="mailto:[email protected]">[email protected]</a> with any questions as they may arise.<br> <br> We look forward to a long and successful partnership with you!<br> <br> <br> Warm Regards,<br> <br> The Atrinsic Affiliate Network Publisher Team<br> <a href="mailto:[email protected]">[email protected]</a>""" msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) msg.attach_alternative(html_content, "text/html") msg.send() except: no_email_sent = True #create_company(publisher) publisher.status = ORGSTATUS_LIVE publisher.date_joined = datetime.datetime.now() publisher.save() #ACE INSERT IF NO MATCHES ARE FOUND matches = search_company(publisher.company_name) if len(matches) > 0: if request.method == 'POST': form = TickerForm(request.POST) if form.is_valid(): publisher.ticker = form.cleaned_data['ticker'] publisher.save() #redirect to new url and template to display list. Chose or create if no_email_sent == True: error_msg = 'An error occured when trying to contact the publisher automaticly to advise him of the approval. Please attempt this manualy. This is likely cause by the publisher not entering valid contact info.' else: error_msg = '' return AQ_render_to_response(request, 'network/search-ace.html', { 'matches': matches, 'orgId': publisher.id, 'error': error_msg, }, context_instance=RequestContext(request)) else: create_company(publisher) if request.method == 'POST': form = TickerForm(request.POST) if form.is_valid(): publisher.ticker = form.cleaned_data['ticker'] publisher.save() return HttpResponseRedirect( '/network/account/publisher/applications/') else: form = TickerForm(initial={ 'ticker': publisher.ticker, }) if no_email_sent == True: return AQ_render_to_response( request, 'network/publisher-applications-deny.html', { 'publisher': publisher, 'error': 'An error occured when trying to contact the publisher automaticly to advise him of the approval. Please attempt this manualy. This is likely cause by the publisher not entering valid contact info.', }, context_instance=RequestContext(request)) else: return AQ_render_to_response( request, 'network/publisher-applications-approve.html', { 'publisher': publisher, 'form': form, }, context_instance=RequestContext(request))