tpy:
import os import tpy_tools import string import KS2 import KS2.ks import KS2.client_tools from KS2.ks import TPY_TOP import json from datetime import datetime, timedelta client = __d.get("client","guest") client_ip = __d.get("client_ip","guest") cappers = KS2.client_tools.CLIENT_TO_CAPPER client_account = KS2.client_tools.Account_Summary(client) preferred_name = { 'nbaguru': 'NBA guru', 'mti': 'MTi Sports Forecasting', 'cajun': 'Cajun Sports', 'sbb': 'SportsBook Breakers', 'nbawiseguys': 'NBA Wiseguys', 'mreast': 'Mr East', 'rtp': 'Roughing The Picker', } logos = { 'nbaguru': 'guru-img.jpg', 'mti': 'mti-img.svg', 'cajun': 'cajun-sdql-img.svg', 'sbb': 'sports-sdql-img.svg', 'nbawiseguys': 'wiseguys-img.svg', 'mreast': 'mr-img.svg', 'rtp': 'rough-img.svg', } logo_sports = { 'nbaguru': 'nbaguru-sports.svg', 'mti': 'mti-sports.svg', 'cajun': 'cajun-sports.svg', 'sbb': 'sbb-sports.svg', 'nbawiseguys': 'nbawiseguys-sports.svg', 'mreast': 'mreast-sports.svg', 'rtp': 'rtp-sports.svg', } logo_headers = { 'nbaguru': 'nbaguru-header.svg', 'mti': 'mti-header.svg', 'cajun': 'cajun-header.svg', 'sbb': 'sbb-header.svg', 'nbawiseguys': 'nbawiseguys-header.svg', 'mreast': 'mreast-header.svg', 'rtp': 'rtp-header.svg' } capper = __d['capper'] logo = logos[capper] purchase = __d.get('purchase', '') purchase_confirm = 0 def convert_format(x): title = re.findall('<font color=880088>(.*?)</font>', x) subtitle = re.findall('<font color=FF0000>(.*?)</font>', x) if len(title) > 0: x = x.replace('<font color=880088>%s</font>'%title[0],'') if len(re.findall('>([^<>]+)</', title[0])) > 0: title = re.findall('>([^<>]+)</', title[0])[0] else: title = title[0] else: title = '' if len(subtitle) > 0: x = x.replace('<font color=FF0000>%s</font>'%subtitle[0],'') if len(re.findall('>([^<>]+)</', subtitle[0])) > 0: subtitle = re.findall('>([^<>]+)</', subtitle[0])[0] else: subtitle = subtitle[0] else: subtitle = '' print(title, subtitle, x) return title.strip(), subtitle.strip(), x.strip('\n').strip("'") def prepare_pick_blurb(title, subtitle, blurb): pick = """ <div class="col-12 flex-between"> <P class="investment-card-detail-header">%s</P> </div> <p class="investment-card-detail-small-header">%s</p> <p class="investment-card-detail-content">%s</p> """%(title, subtitle, blurb) return pick def view_pay(client_id, picks_name, active, selection, selection_index, subscriber, purchase, client_ip = client_ip, KS2=KS2): # selection = selections[selection_index] posted_amount = selection.get("amount",0) amount = selection.get("amount",0) if subscriber: amount = 0 # for trend sets we don't want to have to change the selection file # so we invent a key word __TODAY and sub out here # Do Not use this with guaranteed picks! # sf_for_item = string.replace(selection_file,"__TODAY","_%s"%today) item = "%s_%s:%d"%(picks_name, active, selection_index + 1) notes = "Guaranteed" * (selection.get("due","Y")=="P" and 0<amount) #default to due client_account = KS2.client_tools.Account_Summary(client_id) # right_td = "<H1>Your Selection</H1>" #print "selections = %s"%selections paid = 0 #see if this guy already bought this one from the same IP (guard against double clickers) for transaction in client_account.transactions: if transaction[1] == item: # and transaction[4] == client_ip: print('ALREADY PAID') paid = 1 break #print "<B>FOO</B>" if paid or (amount <= client_account.balance) or (amount==0): if amount and purchase == item and not paid: #only deduct/log when viewed for the first time KS2.client_tools.log_pick(client_id,client_ip,item) message = KS2.client_tools.transaction(client_id,client_id, amount=-amount, item = item, ip_address = client_ip, notes = notes) print('H', amount, purchase, item, paid) if message == 'transaction completed': print('MESSAGE', message) if 'package|%s'%picks_name in selection['text'].lower(): key = "free %s selections"%picks_name value = selection['text'].split('|')[-2] now_tuple = time.localtime(time.time()+int(value)*3600*24) value = "%4d%0.2d%0.2d2359"%(now_tuple[0],now_tuple[1],now_tuple[2]) foo=KS2.client_tools.assign_to_info(client_id,key,value,overwrite=1) return 1 else: return 0 elif purchase != item and amount > 0 and not paid: return 0 else: return 1 # right_td = right_td + htmlize(selection["text"]) # # #print "not paid" # KS2.client_tools.log_pick(client_id,client_ip,item) # KS2.client_tools.transaction(client_id,client_id, amount=-amount, item = item, ip_address = client_ip, notes = notes) else: return 0 bio = "<p></p>" if '%s.tpy'%(capper) in os.listdir('/home/kscREV1/KS/Tpy/KC/Bio/'): bio = tpy_tools.build_page(os.path.join(KS2.ks.TPY_TOP,'KC','Bio',"%s"%(capper)),__d) bio = '<p>' + bio + '</p>' blurbs = ""; supported_sports = ""; all_selections = ''; for sport in ['nfl','nba','mlb','ncaafb','ncaabb', 'wnba']: if '%s_%s.json'%(capper, sport.lower()) in os.listdir('/home/kscREV1/KS/Tpy/KC/Status/'): print(sport, 1) show = json.load(open(os.path.join('/home/kscREV1/KS/Tpy/KC/Status','%s_%s.json'%(capper, sport.lower())), 'r')) if show['sl-blurb'] == ' checked': print(sport, 2) if "%s_%s.tpy"%(capper, sport.lower()) in os.listdir('/home/kscREV1/KS/Tpy/KC/Blurb/'): # print(sport,3) blurb = tpy_tools.build_page(os.path.join(KS2.ks.TPY_TOP,'KC','Blurb',"%s_%s"%(capper, sport.lower())),__d) # print('BLURB',blurb) blurb = blurb.split('<AdYq7>') blurb_stat = datetime.strptime(blurb[-1].strip('\n'), '<expires:%Y%m%d%H%M>') blurb = blurb[0] if blurb_stat > (datetime.now() + timedelta(3/24)): blurbs += """ <div class="investment-record-card w-card item-center"> <div class="col-12 flex-between"> <img class="wow fadeInLeft" src="/Images/investments/%s" alt="#"> <img class="wow fadeInRight" src="/Images/investments/%s.svg"> </div> <p class="investment-card-content">%s</p></div> """%(logo_sports[capper], sport.upper()[0:5], blurb) supported_sports += '<img src="/Images/investments/%s.svg" alt="title">'%(sport.upper()[0:5]) # if show['sl-package'] == ' checked': picks_name = '%s_%s'%(capper, sport.lower()) # if client in cappers: subscriber = 1 elif KS2.client_tools.expired(KS2.client_tools.info(client).get("free %s selections"%picks_name,"000000000000")): subscriber = 0 else: subscriber = 1 # selection_dir = os.path.join('/home/kscREV1/KS/Source/../Pick/',picks_name) if os.path.exists(selection_dir): if 'active' in os.listdir(selection_dir): active_file = string.strip(open(os.path.join(selection_dir,"active"),"r").read()) selections = KS2.client_tools.import_file(selection_dir, active_file).selections i = 0 for s in selections: if 'expire' in s: T = s['expire'] else: T = 000000000000 try: expiration = datetime.strptime('%s/%s/%s %s:%s'%(T[0:4], T[4:6], T[6:8], T[8:10], T[10:12]), '%Y/%m/%d %H:%M') except ValueError: continue tnow = (datetime.now()+timedelta(hours=3)) if ((tnow < expiration)): # or ('package|' in s['text'])): purchased = view_pay(client, picks_name, active_file, s, i, subscriber, purchase) purchase_confirm = max(purchase_confirm, purchased) print('PURCH', purchased) if type(s['amount']) == str: cost = s['amount'] else: cost = ('%s'%(s['amount'])).strip('0').strip('.') if 'card-detail-header' not in s['blurb']: title, subtitle, blurb = convert_format(s['blurb']) s['blurb'] = prepare_pick_blurb(title, subtitle, blurb) subscriber_link = '<button class="button-primary-card button-color-card px-16-card" onclick="showSel(`%s`)"><a class="no-underline">View Selection</a></button>'%(s['text'].replace('"',"'")) customer_link = '<button id="%s_%s___%s" class="button-primary-card button-color-card px-16-card" onclick="getSel(event)"><a class="no-underline" href="">Purchase for %s Web Credits</a></button>'%(picks_name, active_file, i+1, cost) guest_link = '<button id="%s_%s___%s" class="button-primary-card button-color-card px-16-card" onclick="reqLogin()"><a class="no-underline" href="">Purchase for %s Web Credits</a></button>'%(picks_name, active_file, i+1, cost) if client in cappers: link = subscriber_link elif purchased == 1: link = subscriber_link elif client == 'guest': link = guest_link elif KS2.client_tools.expired(KS2.client_tools.info(client).get("free %s selections"%picks_name,"000000000000")): link = customer_link else: link = subscriber_link selection = """ <div class="col-xl-6 col-lg-6 col-md-12 %s"> <!-- Start Card-3 Area --> <div class="investment-card-detail item-center"> <div class="col-12 flex-between"> <img class="" src="/Images/investments/%s"> <img class="" src="/Images/investments/%s.svg"> </div> %s <div class="field-card button-field"> %s </div> </div> <!-- End Card-3 Area --> </div> """%(capper, logo_headers[capper], sport.upper()[0:5], s['blurb'], link) all_selections += selection i += 1 all_samples = ''; record = '' if os.path.exists(os.path.join('/home/kscREV1/KS/Tpy/KC/Status','%s_main.json'%(capper))): show_main = json.load(open(os.path.join('/home/kscREV1/KS/Tpy/KC/Status','%s_main.json'%(capper)), 'r')) if show_main['sl-package'] == ' checked': selection_dir = '/home/kscREV1/KS/Source/../Tpy/KC/Sample/' if os.path.exists(selection_dir): active_file = capper samples = KS2.client_tools.import_file(selection_dir, active_file).selections for s in samples: link = '<button class="button-primary-card button-color-card px-16-card" onclick="showSel(`%s`)"><a class="no-underline">View Sample</a></button>'%(s['text']) sample = """ <div class="col-xl-6 col-lg-6 col-md-12 %s"> <!-- Start Card-3 Area --> <div class="investment-card-detail item-center"> <div class="col-12 flex-between"> <img class="" src="/Images/investments/%s"> <img class="" src="/Images/investments/%s.svg"> </div> %s <div class="field-card button-field"> %s </div> </div> <!-- End Card-3 Area --> </div> """%(capper, logo_headers[capper], 'SAMPLE', s['blurb'], link) all_samples += sample if show_main['sl-record'] == ' checked': selection_dir = '/home/kscREV1/KS/Source/../Tpy/KC/Record/' if os.path.exists(selection_dir): active_file = capper record_context = tpy_tools.build_page(os.path.join(KS2.ks.TPY_TOP,'KC','Record',"%s"%(capper)),__d) record = """ <div class="investment-record-card w-card item-center" onmouseover="document.getElementById('drop-control').style.opacity = 1" onmouseleave="document.getElementById('drop-control').style.opacity = 0; document.getElementById('record-content').style.height = 0" onclick="document.getElementById('record-content').style.height = document.getElementById('record-content').scrollHeight" style="cursor:pointer"> <div class="col-12 flex-between"> <p style="color: rgb(30 103 58);font-size: 22px;font-weight: 600;">Capper Stats / Historical Records</p> <p id="drop-control" class="record-control">+</p> <!--<img id = "drop-control" class="wow fadeInRight" src="/Images/investments/%s.svg" onclick="document.getElementById('record-content').style.height = 'auto'">--> </div> <div id="record-content" class="record-content investment-card-content">%s</div></div> """%('RECORD', record_context)
error:
exception:
message: invalid syntax (, line 2)
traceback:


error:
exception:
message: 'capper'
traceback: