python Logic mixup with krakenapi - python-3.x

Can anyone see the mistake in code
def add_kraken_order():
url = 'https://api.kraken.com/0/private/AddOrder'
key = 'PuwrA+0sssssssssNOTREALsssssssssssssssssq5qj'
secret = 'NVZh7FlQBpssNOTREALssssssssssKBwq4CYSSIjspXR6XGg=='
pair = 'XXBTZEUR'
buysell = 'buy'
ordertype = 'limit'
volume = '1'
orderinfo = ('AddOrder', {'pair': pair,'type' : buysell,
'ordertype' : ordertype, 'volume' : volume,})
market='https://api.kraken.com/0/private/AddOrder'
rr=request.post.market(orderinfo)

Related

Validate WTF Flask Form Input Values

I have the following form in my flask app. I'd like to ensure that the input value is actually an integer and also if the value entered in token > k here k can be some number it spits an error message to the screen. The IntegerField doesn't seem to enforce integer values, e.g., if the user enters 2.3 it passes that to my function which fails because it expects an integer.
Can this type of error message happen in the form or do I need to program that inside my flask app once the value is passed from the form to the server?
class Form(FlaskForm):
token = IntegerField('Token Size', [DataRequired()], default = 2)
submit = SubmitField('Submit')
EDIT
Per the comment below, updating this with my revised Form and the route
class Form(FlaskForm):
token = IntegerField('Token Size', validators=[DataRequired(), NumberRange(min=1, max=10, message='Something')], default = 2)
ngram_method = SelectField('Method', [DataRequired()],
choices=[('sliding', 'Sliding Window Method'),
('adjacent', 'Adjacent Text Method')])
rem_stop = BooleanField('Remove Stop Words', render_kw={'checked': True})
rem_punc = BooleanField('Remove Punctuation', default = True)
text2use = SelectField('Text To Use for Word Tree', [DataRequired()],
choices=[('clean', 'Clean/Processed Text'),
('original', 'Original Text String')])
pivot_word = TextField('Pivot Word for Word Tree', [DataRequired()])
submit = SubmitField('Submit')
And the route in which the form is used
#word_analyzer.route('/text', methods=('GET', 'POST'))
def text_analysis():
form = Form()
result = '<table></table>'
ngrams = '<table></table>'
orig_text = '<table></table>'
text = ""
if request.method == 'POST':
tmp_filename = tempfile.gettempdir()+'\\input.txt'
if request.files:
txt_upload = request.files.get('text_file')
if txt_upload:
f = request.files['text_file']
f.save(tmp_filename)
if os.path.exists(tmp_filename):
file = open(tmp_filename, 'r', encoding="utf8")
theText = [line.rstrip('\n') for line in file]
theText = str(theText)
token_size = form.token.data
stops = form.rem_stop.data
punc = form.rem_punc.data
ngram_method = form.ngram_method.data
text_result = text_analyzer(theText, token_size = token_size, remove_stop = stops, remove_punctuation = punc, method = ngram_method)
result = pd.DataFrame.from_dict(text_result, orient='index', columns = ['Results'])[:-3].to_html(classes='table table-striped table-hover', header = "true", justify = "center")
ngrams = pd.DataFrame.from_dict(text_result['ngrams'], orient='index', columns = ['Frequency']).to_html(classes='table table-striped table-hover', header = "true", justify = "center")
if form.pivot_word.data == None:
top_word = json.dumps(text_result['Top Word'])
else:
top_word = json.dumps(form.pivot_word.data)
if form.text2use.data == 'original':
text = json.dumps(text_result['original_text'])
else:
text = json.dumps(text_result['clean_text'])
if form.validate_on_submit():
return render_template('text.html', results = [result], ngrams = [ngrams], form = form, text=text, top_word = top_word)
return render_template('text.html', form = form, results = [result],ngrams = [ngrams], text=text, top_word='')
Use the NumberRange validator from wtforms.validators.NumberRange. You can pass an optional Min and Max value along with the error message. More info here
Update
# Form Class
class Form(FlaskForm):
token = FloatField('Token Size', validators=[DataRequired(), NumberRange(min=1, max=10, message='Something')])
# Route
if form.validate_on_submit():
print(form.name.data)
Here is an example that should work, make sure your form class field looks similar and also that in your route you use form.validate_on_submit():.

Why didn't the text come out?

I have created the recommended modules and comments for the student competencies database. But what's wrong, why did it not appear?
Here is the screenshot for this:
screenshot
DatabasehelperCompetencies.java
LearnerInformation.java
RecommendedModule.java
I got the code
Intent intent = getIntent();
if(intent != null) {
id = intent.getStringExtra("id");
loginName = intent.getStringExtra("name");
studentName = intent.getStringExtra("studentName");
Competencies = intent.getStringExtra("title");
Answer1 = intent.getStringExtra("answer1");
Answer2 = intent.getStringExtra("answer2");
Answer3 = intent.getStringExtra("answer3");
Answer4 = intent.getStringExtra("answer4");
RecommendedModule = intent.getStringExtra("recommendedModule");
StudentComments = intent.getStringExtra("studentComments");
}
getId = Integer.parseInt(id);
login_Name.setText(loginName);
studentname.setText(studentName);
competencies.setText(Competencies);
answer1.setText(Answer1);
answer2.setText(Answer2);
answer3.setText(Answer3);
answer4.setText(Answer4);
recommendedModule.setText(RecommendedModule);
comments.setText(StudentComments);

Python PonyORM One to one mapping

I am trying to create a one-to-one mapping using Pony ORM.
class ApplierIngress(ApplierObjectMapper.db.Entity):
correlation_id = orm.PrimaryKey(str)
ticket_number = orm.Required(str)
username = orm.Required(str)
status = orm.Required(str)
request_date = orm.Required(datetime)
class ApplierResult(ApplierObjectMapper.db.Entity):
correlation_id = orm.Required(ApplierIngress)
result = orm.Required(orm.LongStr)
request_date = orm.Required(datetime)
It throws error while generating the mapping
pony.orm.core.ERDiagramError: Reverse attribute for ApplierResult.correlation_id not found
I want correlation_id in ApplierResult table be the foreign key referencing to correlation_id in ApplierIngress table
Please let me know what am I doing wrong?
As error said you need to specify reverse attribute. Entities is not just Tables.
class ApplierIngress(ApplierObjectMapper.db.Entity):
correlation_id = orm.PrimaryKey(str)
ticket_number = orm.Required(str)
username = orm.Required(str)
status = orm.Required(str)
request_date = orm.Required(datetime)
result_id = orm.Optional('ApplierResult') # this attribute should be added
class ApplierResult(ApplierObjectMapper.db.Entity):
correlation_id = orm.Required(ApplierIngress)
result = orm.Required(orm.LongStr)
request_date = orm.Required(datetime)
Since this class is not yet declared you should use it as string or lambda
result_id = orm.Optional('ApplierResult')
result_id = orm.Optional(lambda: ApplierResult)
See here

how to update all legal entity in stripe through api

How to update all legal entity in stripe through API?
Thanks in advance. When run this, it throws errors like invalid arguments
\Stripe\Stripe::setApiKey("");
$account = \Stripe\Account::retrieve("");
$account->first_name = "555-867-5309";
$account->save();
$acc_details = \Stripe\Account::retrieve('');
$acc_details->legal_entity['first_name'] = 'First Name';
$acc_details->legal_entity['last_name'] = 'Last Name';
$acc_details->legal_entity['dob']['day'] = '04';
$acc_details->legal_entity['dob']['month'] = '05';
$acc_details->legal_entity['dob']['year'] = '1980';
$acc_details->legal_entity['type'] = 'individual';//Either “individual” or “company”
$acc_details->legal_entity['address']['city'] = 'Abbotsford';
$acc_details->legal_entity['address']['country'] = 'CA';
$acc_details->legal_entity['address']['line1'] = '33415 Maclure Rd';
$acc_details->legal_entity['address']['line2'] = '33415 Maclure Rd';
$acc_details->legal_entity['address']['postal_code'] = 'V2S 7W2';
$acc_details->legal_entity['address']['state'] = 'BC';
$acc_details->legal_entity['personal_id_number'] = '056464654';

Using ClassificationAttributeValueTranslator on impex

I'm trying to use the ClassificationAttributeValueTranslator on an impex. I have some examples with the class ClassificationAttributeTranslator working but can't make this work.
$productCatalog = myCatalog
$classificationCatalog = myClassification
$catalogVersion = catalogversion(catalog(id[default = $productCatalog]), version[default = 'Staged'])[unique = true, default = $productCatalog:Staged]
$clAttrModifiers = system = '$classificationCatalog', version = '1.0', translator = de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeValueTranslator, lang = es
//Q_1001 is the ClassAttributeAssignment ID
$feature1 = #Q_1001 [$clAttrModifiers];
//123012 is the product code and
INSERT_UPDATE Product; code[unique = true]; $feature1; $catalogVersion
; 123012 ; TEST VALUE;
I'm getting this error
INSERT_UPDATE Product;code[unique = true];#Q_1001 [system = 'myClassification', version = '1.0', translator = de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeValueTranslator, lang = es];catalogversion(catalog(id[default = myCatalog]), version[default = 'Staged'])[unique = true, default = myCatalog:Staged];# invalid special value translator class 'de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeValueTranslator' - cannot create due to java.lang.InstantiationException: de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeValueTranslator
,,,,invalid special value translator class 'de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeValueTranslator' - cannot create due to java.lang.InstantiationException: de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeValueTranslator;123012;TEST VALUE;
You have to use de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeTranslator and not de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeValueTranslator

Resources