How to verify web text while excluding random vars with ruby/watir - ruby

I have this text and need to verify the bolded words only in each line:
Insured Direct Bill / 16.67%: $xxx.xx down, includes the Policy Fee and Financial Responsibility Fee, and 5 installments of $xxx.xx (does not include $x.xx installment fee)
Insured Direct Bill / 25%: $xxx.xx down, includes the Policy Fee and Financial Responsibility Fee, and 5 installments of $xxx.xx (does not include $x.xx installment fee)
Electronic Funds Transfer: $xxx.xx down, includes the Policy Fee and Financial Responsibility Fee, and 5 installments of $xxx.xx (does not include $x.xx installment fee)
I'm assuming I'll need to use:
foo = REGEX
#browser.text.include?(foo)
I'm stuck at how to get it to see everything other than the currency amounts. [^$\d+.\d+] excludes all the currency but includs the 5 and 16.67
Thanks

regex = /Insured Direct Bill \/ 25%: \$(\d+\.\d+) down, includes the Policy Fee and Financial Responsibility Fee, and 5 installments of \$(\d+\.\d+) \(does not include \$(\d+\.\d+) installment fee\)/
#browser.text.match(regex)

There are some regex lessons in Marick's book Everyday Scripting with Ruby. I recommend them to strengthen your capability if you need to use regex from time to time.

Related

NEAR Marketplace - How should I charge the transaction fee on each sales?

We're building a marketplace in NEAR. We have two smart contracts for token and marketplace. Same as NEAR example.
In our platform, we have successfully implemented below features:
Token mint (used contract method: nft_mint)
Token listing for sale in marketplace (used contract methods: storage_deposit nft_approve)
Token purchase (used contract method: offer)
Everything is working fine.
Now, we want to charge the transaction fee (2.5%) on each sales for our marketplace.
--
I did one mint and buy test with Paras Marketplace to observe the royalty and transaction fee distribution. Here is the test details:
With seller.near account, I minted an NFT in Paras Marketplace. And added 3% royalty. And listed it #1 Ⓝ for sale.
With buyer.near account, bought it with another account.
NFT Details:
Name : My Non-fungible token #1
Listed Price : 1 Ⓝ
Royalty : 3%
Sale Breakdown:
Receive (Seller) : 0.95 Ⓝ
Royalty (Creator) : 0.03 Ⓝ
Fee (Paras) : 0.02 Ⓝ
Before purchase - Account Balance
buyer.near : 50.03995 Ⓝ
seller.near : 4.896 Ⓝ
After purchase (1st sale after minted) - Account Balance
buyer.near : 49.03388 Ⓝ | Difference : -1.00607 Ⓝ
seller.near : 5.82587 Ⓝ | Difference : +0.92987 Ⓝ
# NFT Create Transaction
This is nft_create_series transaction. Where Paras is sending "transaction_fee": "200" to charge 2% service fee on each sale:
# NFT Buy Transaction
This is buy transaction. Where Paras charged 2% service fee:
Question:
We want to charge 2.5% service fee on each sales.
We want to implement "transaction_fee": "250" object in our marketplace contract.
How to do the same with our marketplace?
There are several ways that you can go about doing this. The two that I would recommend are the following (I saw you were following along with the zero to hero tutorial):
Option A (simplest) - store your account in the perpetual royalties object for the token when it is minted.
This is the easiest to implement as you don't need to change anything in your contracts and you simply need to alter what is passed into the royalties object on mint.
This requires that you have control over the NFT contract.
This allows you to receive royalties on whatever marketplace the token is sold on since the royalties are stored on the token level in the NFT contract.
This allows you to specify which account should receive the royalties instead of forcing the marketplace contract to store the funds.
Option B - before calling nft_transfer_payout in your marketplace contract, subtract 2.5% from the price object. This will result in your marketplace contract keeping the 2.5% and paying out the remaining 97.5% to the respective accounts.
With this approach, since many accounts are paying for storage, your contract has funds that aren't all withdraw-able by you. You should keep a tally on how much $NEAR you've received so that you can withdraw that amount and not accidentally withdraw too many funds that may have "belonged" to someone else via storage deposits.

How to wrap the first 10 commas with double quotes?

Here is my input.csv file
dealerid,address,city,state,zip,vin,stocknumber,type,color,year,make,model,trim,bodystyle,fueltype,mileage,transmission,interiorcolor,interiorfabric,price,titlestatus,warranty,options_text,cylinders,engine,engineaspiration,enginetext,drivetrain,transmissiontext,mpgcity,mpghighway,features_text,vdc_url,images
TS06095298,999 wanna Road,Windsor,CT,06095,22HDT13S922218113,298,Used,Red,2002,OLDSMOBILE,BRAVADA,,,,136000,AUTOMATIC,,,2200,Clear,Available,"This vehicle is offered for sale by a verified private seller and features: FREE vehicle history & title report. Original window sticker available. Seller`s identity, email and phone verified. Secure cashless transactions. No cash needed. Pay securely by debit card or ACH. Bill of Sale and receipt issued for completed transactions. Vehicle financing options may be available.",,,,,,,,,,https://www.example.com/listings/298,"https://www.example.com/rails/00008.jpg,https://www.example.com/rails/AM00010.jpg"
TS06095298,999 wanna Road,Windsor,CT,06095,22HDT13S922123453,307,Used,Brown,2008,HONDA,599,,,,217538,AUTOMATIC,,,3500,Clear,Available,"This vehicle is offered for sale by a verified private seller and features: FREE vehicle history & title report. Original window sticker available. Seller`s identity, email and phone verified. Secure cashless transactions. No cash needed. Pay securely by debit card or ACH. Bill of Sale and receipt issued for completed transactions. Vehicle financing options may be available.",,,,,,,,,,https://www.example.com/listings/211,"https://www.example.com/rails/00008.jpg,https://www.example.com/rails/AM00010.jpg"
I need to wrap all columns with double quotes so I end up with a file like so:
"dealerid","address","city","state","zip","vin","stocknumber","type","color","year","make","model","trim","bodystyle","fueltype","mileage","transmission","interiorcolor","interiorfabric","price","titlestatus","warranty","options_text","cylinders","engine","engineaspiration","enginetext","drivetrain","transmissiontext","mpgcity","mpghighway","features_text","vdc_url","images"
"TS06095298","999 wanna Road,Windsor","CT","06095","22HDT13S922218113","298","Used","Red","2002","OLDSMOBILE","BRAVADA","","","","136000,AUTOMATIC","","","2200","Clear","Available","This vehicle is offered for sale by a verified private seller and features: FREE vehicle history & title report. Original window sticker available. Seller`s identity, email and phone verified. Secure cashless transactions. No cash needed. Pay securely by debit card or ACH. Bill of Sale and receipt issued for completed transactions. Vehicle financing options may be available.","","","","","","","","","","https://www.example.com/listings/298","https://www.example.com/rails/00008.jpg,https://www.example.com/rails/AM00010.jpg"
"TS06095298","999 wanna Road,Windsor","CT","06095","22HDT13S922123453","307","Used","Brown","2008","HONDA","599","","","","217538","AUTOMATIC","","","3500","Clear","Available","This vehicle is offered for sale by a verified private seller and features: FREE vehicle history & title report. Original window sticker available. Seller`s identity, email and phone verified. Secure cashless transactions. No cash needed. Pay securely by debit card or ACH. Bill of Sale and receipt issued for completed transactions. Vehicle financing options may be available.","","","","","","","","","","https://www.example.com/listings/211","https://www.example.com/rails/00008.jpg,https://www.example.com/rails/AM00010.jpg"
The file is pretty constant throughout with the same missing data from certain columns.
The images column and the features text column come wrapped already.
Seeing the same info was missing throughout I decided to add double quotes to the beginning of each line and started to replace the commas with double quotes but started running into some issues.
Here is what I have so far. I know the code is not very efficient but it's a start.
#!/bin/bash
#- Temp Directories
tmp_dir="$(mktemp -d -t 'csv.XXXXX' || mktemp -d 2>/dev/null)"
tmp_input1="${tmp_dir}/temp_input1.csv"
tmp_input2="${tmp_dir}/temp_input2.csv"
tmp_input3="${tmp_dir}/temp_input3.csv"
#- Variables
client="00000"
wDir="$(pwd)"
ftpDir="${wDir}/.clientftp"
clientDir="${ftpDir}/${client}"
csvFile="${clientDir}/final.csv"
inputCsv="${wDir}/input.csv"
# Lets Begin
cd "$wDir" || exit
cp "$inputCsv" "$tmp_input1"
dos2unix "$tmp_input1"
# place first line to a temp file , surrounding commas with double quotes , adding double quotes to the front and end of line
head -1 "$tmp_input1" | sed -e 's/,/","/g;s/.*/"&"/' > "$tmp_input2"
# place remainding lines to a temp file
sed 1,1d "$tmp_input1" | sed "s/^/\"/" > "$tmp_input3"
sed -i 's/",,,,,,,,,,https/","","","","","","","","","","https/g' "$tmp_input3"
sed -i 's/,Clear,Available,"/","Clear","Available","/g' "$tmp_input3"
sed -i 's/,,,,/","","","","/g' "$tmp_input3"
sed -i 's/,,,/","","","/g' "$tmp_input3"
# Create final file
cat "$tmp_input2" > "$csvFile"
cat "$tmp_input3" >> "$csvFile"
rm -rf "$tmp_dir"
{ clear; echo ""; echo ""; echo "nano $csvFile"; echo ""; }
nano "$csvFile"
This script produces:
"dealerid","address","city","state","zip","vin","stocknumber","type","color","year","make","model","trim","bodystyle","fueltype","mileage","transmission","interiorcolor","interiorfabric","price","titlestatus","warranty","options_text","cylinders","engine","engineaspiration","enginetext","drivetrain","transmissiontext","mpgcity","mpghighway","features_text","vdc_url","images"
"TS06095298,999 wanna Road,Windsor,CT,06095,22HDT13S922218113,298,Used,Red,2002,OLDSMOBILE,BRAVADA","","","","136000,AUTOMATIC","","","2200","Clear","Available","This vehicle is offered for sale by a verified private seller and features: FREE vehicle history & title report. Original window sticker available. Seller`s identity, email and phone verified. Secure cashless transactions. No cash needed. Pay securely by debit card or ACH. Bill of Sale and receipt issued for completed transactions. Vehicle financing options may be available.","","","","","","","","","","https://www.example.com/listings/298,"https://www.example.com/rails/00008.jpg,https://www.example.com/rails/AM00010.jpg"
"TS06095298,999 wanna Road,Windsor,CT,06095,22HDT13S922123453,307,Used,Brown,2008,HONDA,599","","","","217538,AUTOMATIC","","","3500","Clear","Available","This vehicle is offered for sale by a verified private seller and features: FREE vehicle history & title report. Original window sticker available. Seller`s identity, email and phone verified. Secure cashless transactions. No cash needed. Pay securely by debit card or ACH. Bill of Sale and receipt issued for completed transactions. Vehicle financing options may be available.","","","","","","","","","","https://www.example.com/listings/211,"https://www.example.com/rails/00008.jpg,https://www.example.com/rails/AM00010.jpg"
So now I have a few issues:
1- The vdc_url column does not have a closing double quote
2- first 10 commas need to be wrapped with double quotes
The last column can contain more than 3 images
Any help would be appreciated.
I like ruby for quick CVS conversions:
ruby -rcsv -e '
out = CSV.instance($stdout, {force_quotes: true})
CSV.foreach(ARGV.shift) {|row| out << row}
' input.csv
make sure you don't have any trailing whitespace on any line.
csvkit would also be a good solution.
With GNU awk for FPAT:
$ awk -v FPAT='[^,]*|"[^"]*"' -v OFS=',' '
{ for (i=1;i<=NF;i++) {gsub(/^"|"$/,"",$i); $i="\"" $i "\""} }
1' file
"dealerid","address","city","state","zip","vin","stocknumber","type","color","year","make","model","trim","bodystyle","fueltype","mileage","transmission","interiorcolor","interiorfabric","price","titlestatus","warranty","options_text","cylinders","engine","engineaspiration","enginetext","drivetrain","transmissiontext","mpgcity","mpghighway","features_text","vdc_url","images"
"TS06095298","999 wanna Road","Windsor","CT","06095","22HDT13S922218113","298","Used","Red","2002","OLDSMOBILE","BRAVADA","","","","136000","AUTOMATIC","","","2200","Clear","Available","This vehicle is offered for sale by a verified private seller and features: FREE vehicle history & title report. Original window sticker available. Seller`s identity, email and phone verified. Secure cashless transactions. No cash needed. Pay securely by debit card or ACH. Bill of Sale and receipt issued for completed transactions. Vehicle financing options may be available.","","","","","","","","","","https://www.example.com/listings/298","https://www.example.com/rails/00008.jpg,https://www.example.com/rails/AM00010.jpg"
"TS06095298","999 wanna Road","Windsor","CT","06095","22HDT13S922123453","307","Used","Brown","2008","HONDA","599","","","","217538","AUTOMATIC","","","3500","Clear","Available","This vehicle is offered for sale by a verified private seller and features: FREE vehicle history & title report. Original window sticker available. Seller`s identity, email and phone verified. Secure cashless transactions. No cash needed. Pay securely by debit card or ACH. Bill of Sale and receipt issued for completed transactions. Vehicle financing options may be available.","","","","","","","","","","https://www.example.com/listings/211","https://www.example.com/rails/00008.jpg,https://www.example.com/rails/AM00010.jpg"

Without proration enabled, any changes made to a customer’s subscription mid-cycle goes into effect immediately

During the implementation of recurring payments using Braintree I encountered a problem.
In documentation I can read: “Without proration enabled, any changes made to a customer’s subscription mid-cycle will go into effect at the beginning of the next cycle.” (https://articles.braintreepayments.com/guides/recurring-billing/recurring-advanced-settings#proration)
But if I edit the subscription to a lower dollar amount in the middle of a billing cycle (without proration on downgrades enabled) e.g. from $100 to $80 and then I edit the subscription to a higher dollar amount (with proration on upgrades enabled) e.g. to $90, the gateway will immediately charge me some amount.
In this situation, I would expect that gateway will not generate any transaction, because downgrade should be effective at the beginning of the next cycle and new subscription price ($90) is lower than initial subscription price (100$).
How can I then reach scenario when transaction on proration upgrade will be generated only if new subscription price is higher than maximum subscription price at the current billing cycle?
I'm a developer at Braintree.
If you kept proration on for both price decreases and increases, in the example you give you would see a credit applied to the subscription balance for the decrease, and then a charge applied against the balance for the increase. If the charge exceeds the subscription balance credit, then your customer would be charged.
A subscription will not be charged in the middle of a billing cycle unless you choose to prorate charges. You could create the scenario you want with logic similar to below. Code snippets are in Ruby since you didn't specify what client library you were using.
First look up the subscription you want to update and find the start date of the current billing period:
subscription = Braintree::Subscription.find("subscription_id")
billing_period_start_date = Date.parse(subscription.billing_period_start_date) # convert String to Date
Then iterate over the status_history events of the subscription, and update the billing_period_max_price if the history event took place after the beginning of this billing cycle and the billing_period_max_price is greater than the previous one:
billing_period_max_price = 0.0
subscription.status_history.each do |history_event|
event_date = Date.parse(history_event.timestamp.strftime('%Y/%m/%d')) # convert Time to Date
event_price = history_event.price.to_f
if event_date >= billing_period_start_date && billing_period_max_price < event_price
billing_period_max_price = event_price
end
end
Finally, if the billing_period_max_price is less than what you want to change the subscription price to, prorate the charges:
Subscription.update(
"subscription_id",
:price => "yourHigherPrice",
:options => { :prorate_charges => true }
)
If you have additional questions, feel free to reach out to Braintree support.

Custom shipping - Free with upgrade option

We offer 2 type of delivery to uk customers
spend over £100 and get it free special delivery
spend under £100 and get it free 1st class record but option of Special Delivery for extra £3.
Cannot work out how to enable to in Magento (1.7.0.2)
So how can I add the free with £3 option for carts less than £100?
So I found this extension: http://www.webshopapps.com/uk/free/matrixrate-shipping-extension.html
This is the table I used:
"Country","Region/State","City","Zip/Postal Code From","Zip/Postal Code To","Order Subtotal From","Order Subtotal To","Shipping Price","Delivery Type"
"GBR","","","","","0","99.99","0","Free 1st Class Recorded"
"GBR","","","","","0","99.99","3","Upgrade to Special Delivery Next Day before 1pm"
"GBR","","","","","100","9999","0","Free Special Delivery Next Day before 1pm"
Which works like a charm - hope this helps

free shipping of a single product in magento

i'm using magento version 1.3.2.4
I want to change a product shipping as free shipping. All other products will be charged for shipping. for this i have done the following steps
Here’s what I did to offer free shipping on one specific product:
First, turn on Free Shipping in your Admin Panel > System > Configuration > Sales > Shipping Methods > Free Shipping.
VERY IMPORTANT: set a bogus Minimum order amount – I used 9999999999.99 because if someone spends that much at my shop in one go, I’m retiring.
Save Config.
Second, go to Admin Panel > Promotions > Shopping Cart Price Rules.
Add New Rule.
Use these exact settings:
Rule Name: free shipping
Description: free shipping
Status: Active
Customer Groups: selected all
Coupon Code: [blank]
Uses Per Coupon: 0
Uses Per Customer: 0
From Date: [today]
Priority: 0
Public in RSS Feed: No
Conditions: [ignored this section]
Actions:
Apply: Fixed amount discount
Discount Amount: 0
Minimum Qty Discount is Applied to: 0
Discount Qty Step (Buy X): 0
Free Shipping: For shipment with matching rule
Stop further rules processing: No
Apply the rule … :
If ALL of these conditions are TRUE:
SKU is [inserted specific SKU]
.
Saved Rule.
this is working for me, but when i first add the product with free shipping, free shipping option is coming, then again when i add another product with shipping, at that point shipping option will come.
upto this point its ok.
but in the final checkout page no shipping is there. Actually one product is with shipping and other is without shipping, so it must be like that.
how can i solve this issue
please help
This is covered for magento 1.3 at length here: magento free shipping
Your solution grants free shipping to an entire order, so that may not work in the way you want. Depending on which shipping services you are using, you could go the hack route of setting the weight to 0, so that FedEx and the like won't count it in shipping calculations.
Otherwise, can you provide more detail on your shipping configuration (other than the free shipping)?
:) look, there is a solution that is much, much simpler :)
under "Catalog" create a new product ("Add Product") and for the "Product Type" choose "Virtual Product".
that's it :) enjoy a product with £0.00 shipping costs.
here is a link to a screenshot (apparently I am new member here and can't post images yet):
http://screencast.com/t/dOmkV3KBkZ
be well,
Helmuts
p.s. made this explanation longer for the needs of those who don't know magento at all.

Resources