string formatting error in python - python-2.6

This is a time critical bug otherwise I wouldn't have posted here and it's also my very first try with django and python so consider accordingly .
I am getting error
%o format: a number is required, not str
in my django app . The place where it shows error :(I am trying to create a message string)
msg_donor = 'Dear %s,\nThank you for contributing to %s \'s fundraising campaign
on Milaap.org. You\'ve made our day.\nRemember, since this is a loan, and not
donation, 100% of your money will come back to you!\nYou will shortly receive
your milaap login details. You can check who your money has gone to and track
your repayments through your account. Be sure to sign up and check your account
regularly for updates.\n\n%s' % (d.name, c.fundraiser_name, regardsStr)
I haven't written any %o in my application andI am wondering how this error can be produced ??

You have 100% of your money in your string. % is a formatting character. Use 100%% of your money to put a literal % in there.
(I'm sort of surprised that Python skipped over the space between % and o, but whatever.)

The problem is being cause by a stray % in your string at: 100%
When you do string formatting, you have to make sure to escape literal % by doing %%
Try this:
msg_donor = """Dear %s,\nThank you for contributing to %s's fundraising campaign
on Milaap.org. You've made our day.\nRemember, since this is a loan, and not
donation, 100%% of your money will come back to you!\nYou will shortly receive
your milaap login details. You can check who your money has gone to and track
your repayments through your account. Be sure to sign up and check your account
regularly for updates.\n\n%s""" % (d.name, c.fundraiser_name, regardsStr)

Related

Writing Capybara expectations to verify phone numbers

I'm using AWS Textract to pull information from PDF documents. After the scanned text is returned from AWS and persisted to a var, I'm doing this:
phone_number = '(555) 123-4567'
scanned_pdf_text.should have_text phone_number
But this fails about 20% of the time because of the non-deterministic way that AWS is returning the scanned PDF text. On occasion, the phone numbers can appear either of these two ways:
(555)123-4567 or (555) 123-4567
Some of this scanned text is very large, and I'd prefer not to go through the exercise of sanitizing the text coming back if I can avoid it (I'm also not good at regex usage). I also think using or logic to handle both cases seems to be a little heavy handed just to check text that is so similar (and clearly near-identical to the human eye).
Is there an rspec matcher that'll allow me to check on this text? I'm also using Capybara.default_normalize_ws = true but that doesn't seem to help in this case.
Assuming scanned_pdf_text is a string and the only differences you're seeing is in spaces then you can just get rid of the spaces and compare
scanned_pdf_text.gsub(/\s+/, '').should eq('(555)123-4567') # exact
scanned_pdf_text.gsub(/\s+/, '').should match('(555)123-4567') # partial
scanned_pdf_text.gsub(/\s+/, '').should have_text('(555)123-4567') # partial

To build a flow using Power Automate to download linked csv report in gmail

I'm trying to create a flow using Power Automate (which I'm quite new to) that can get the link/URL in an email I receive daily, then download the .csv file that normally a click to the link would do, and then save the file to a given local folder.
An example of the email I get:
Screenshot of the email I get daily
I searched in Power Automate Community and found this insightful LINK post & answer almost solved it. However, after following the steps and built the flow, it kept failing at the Compose step.
Screenshot of the Flow & Error Message
The flow
Error message
Expression used:
substring(body('Html_to_text'),add(indexOf(body('Html_to_text'),'here'),5),sub(indexOf(body('Html_to_text'),'Name'),5))
Seems the expression couldn't really get the URL/Link? I'm not sure and searched but couldn't find any more posts that can help.
Please kindly share all insights on approaches or workarounds that you think may help me solve the problem and truly thanks!
PPPPPPPPisces
We need to breakdown the bits of the function here which needs 3 bits of info
substring(1 text to search, 2 starting position of the text you want, 3 length of text)
For example, if you were trying to return an unknown number from the text dog 4567 bird
Our function would have 3 parts.
body('Html_to_text'), this bit gets the text we are searching for
add(indexOf(body('Html_to_text'),'dog'),4), this bit finds the position in the text 4 characters after the start of the word dog (3 letters for dog + the space)
sub(sub(indexOf(body('Html_to_text'),'bird'),2)),add(indexOf(body('Html_to_text'),'dog'),4)), I've changed the structure of your code here because this part needs to return the length of the URL, not the ending position. So here, we take the position of the end of the URL (position of the word bird minus two spaces) and subtract it from the position of the start of the URL (position of the word dog + 4 spaces) to get the length.
In your HTML to text output, you need to check what the HTML looks like, and search for a word before the URL starts, and a word after the URL starts, and count the exact amount of spaces to reach the URL. You can then put those words and counts into your code.
More generally, when you have a complicated problem that you need to troubleshoot, you can break it down into steps. For example. Rather than putting that big mess of code into a single block, you can make each chunk of the code in its own compose, and then one final compose to bring them all together - that way when you run it you can see what information each bit is giving out, or where it is failing, and experiment from there to discover what is wrong.

Can I use Ruby Cucumber Watir to Solve a Key Pass to URL puzzle?

I am a NEWBIE. Any help is appreciated.
I've been given the challenge of automating a Key Pass challenge.
a URL is provided (this is an example, I don't think the creator of the challenge wants it in public): www.guessmypasskey.com
When you visit the site, the body text simple returns, Key Denied:
If you add the following path, www.guessmypasskey/?key=a the site will return: Key Denied:00
The key is only alphanumeric and of unknown length...through manual testing I was able to find the key by determining that the binary code returns meant the following: 00 not a character used, 01 character used, wrong position, 11 correct character, correct position.
I envision, opening a browser to the URL with watir, checking a-a, A-Z, 0-9, in the first position...if 00 is displayed on page, delete character from possibility, if 01 is present write the number to a file (this will determine the character length needed.
Basic question, Am I going the wrong direction? Trying to automate with Ruby Cucumber Watir?
I know additional steps will be needed t determine the order of the characters....I'm just trying to get started on the first step, confirming the validity of the characters and the length of the pass key.
Kind of disappointed that the URL the real one. =p
Anyways, that approach would work... but I would imagine it being massive overkill.
Instead, what I would do is simply create a simple Node.js script (using JavaScript) which basically just loops through all possible combinations for each character, stepping through as you move.
You can just use the simple "request" module to request the web page. Then just build up your string like that.
var request = require('request');
// Gets content of one call... add this to your loop somehow.
request({uri: 'http://guessmypasskey.com?key=' + key}, function (err, response, body) {
// body has the result to check
});
This is probably going to be infinitely easier than setting up the tech stack you were talking about... not to mention a lot faster.
Your general approach (ignoring technology) sounds pretty spot on.

Convert to E164 only if possible?

Can I determine if the user entered a phone number that can be safely formatted into E164?
For Germany, this requires that the user started his entry with a local area code. For example, 123456 may be a subscriber number in his city, but it cannot be formatted into E164, because we don't know his local area code. Then I would like to keep the entry as it is. In contrast, the input 089123456 is independent of the area code and could be formatted into E164, because we know he's from Germany and we could convert this into +4989123456.
You can simply convert your number into E164 using libphonenumber
and after conversion checks if both the strings are same or not. If they're same means a number can not be formatted, otherwise the number you'll get from library will be formatted in E164.
Here's how you can convert
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
String formattedNumber = phoneUtil.format(inputNumber, PhoneNumberFormat.E164);
Finally compare formattedNumber with inputNumber
It looks as though you'll need to play with isValidNumber and isPossibleNumber for your case. format is certainly not guaranteed to give you something actually dialable, see the javadocs. This is suggested by the demo as well, where formatting is not displayed when isValidNumber is false.
I also am dealing with this FWIW. In the context of US numbers: The issue is I'd like to parse using isPossibleNumber in order to be as lenient as possible, and store the number in E164. However then we accept, e.g. +15551212. This string itself even passes isPossibleNumber despite clearly (I think) not being dialable anywhere.

mortgage calculator in Shoes but it won't divide?

I am new to Ruby and Shoes, I think I have everything. the program appears to work correctly except when I get to the last step. I, enter the loan amount, interest rate, in to edit_lines, when I press the calculate button, it performs the calculations, stores the calculated numbers to a variable. The last step is dividing the total loan (loan and interest) by the length of the loan in months to ge the monthly payment, so I can make a payment table for the entire loan, but I either get in-corredt results or I get no reeults.
I think I converted the integers to floats, etc. , but... not sure. It appears to add, multiply, subtrct, except it will not divide 2 qbjects. If I enter numbers it works ok.
What am I doing wrong. It does seem like it is that difficult. Example code of dividng the values in a varible by the value of another varible?
It looks like you're using eval(), which you almost never, ever want to use. You can do the exact same thing in normal ruby. I'm just guessing right now since the code I can see in your comment is lacking newlines, but I think this code would work:
#numberbox3.text = #totalinterest + #loadamount
#numberbox5.text = #totalloan / #lengthyears
Hope this helps!

Resources