Extract 'p' data from 'div' with Class of div = "" - python-3.x

I am trying to extract the data in the div with "" as className followed by p tag.
My html looks like this
<div class=""><p>I've been with USAA since 1981 - they've been a good, helpful company and easy to deal with except with making payments on their website. Every time I try to make a payment the website has a problem and I end up calling them. Today, I tried to make a credit card update (same account, different exp. date and code) before I made a payment. The website kept telling me it wouldn't accept the information.</p><p>I called the company to make the payment and was told the system had accepted the information but I couldn't make the payment until tomorrow because of the update. They refused to let me make my payment by phone. 4 times in the past 2 years it wouldn't accept my password, even after I confirmed it by - yes calling in. Other payments have not been accepted for unknown reasons - I've had to call them in. No point having a website if it doesn't work. I avoid calling because it takes so many steps to reach a live person. It's a minor complaint but it happens every time.</p></div></div>
I am using Beautifulsoup and my code to extarct this data is :
reviewAllList = [row.text for row in soup.find_all('div',attrs={"class" : ""})]
However, I am not able to extarct the correct data from the same. Is it that I am missing something? I am using Python 3.5.

Use lambda to find all divs with an empty class attribute andthe first child is a p
rows = [str(row.get_text(strip=True)) for row in soup.find_all(lambda tag: tag.name == "div" and ("class" not in tag.attrs or not len(" ".join(tag["class"]))) and tag.findChildren()[0].name == "p")]

You can just print the text only by saying.
sometxt = <div class=""><p>I've been with USAA since 1981 - they've been a good, helpful company and easy to deal with except with making payments on their website. Every time I try to make a payment the website has a problem and I end up calling them. Today, I tried to make a credit card update (same account, different exp. date and code) before I made a payment. The website kept telling me it wouldn't accept the information.</p><p>I called the company to make the payment and was told the system had accepted the information but I couldn't make the payment until tomorrow because of the update. They refused to let me make my payment by phone. 4 times in the past 2 years it wouldn't accept my password, even after I confirmed it by - yes calling in. Other payments have not been accepted for unknown reasons - I've had to call them in. No point having a website if it doesn't work. I avoid calling because it takes so many steps to reach a live person. It's a minor complaint but it happens every time.</p></div></div>
and now just print(sometxt.text)
if you're only looking for the div class= > "" <
You can print it by print(sometxt['class']) remember that you might have to itterate through your findAll with a for loop to do this.(if there's multiple class)
**row.text**

I assume you just want to get the text from the paragraphs.
You could do something like:
mydiv = soup.find("div", { "class" : "" })
for p in mydiv.find_all('p'):
text_list.append(p.get_text())
or
mydiv = soup.find("div", { "class" : "" })
text = mydiv.find('p').get_text()
Can not test right now, but from my experience with BS this should work fine.
Edit: tested and corrected it.

Related

Use One TradingView Strategy for Multiple Coins connected to Bot

I'm a newbie for TradingView and have been learning a lot. I'm developing a strategy with backtesting using pine-script language however what confusing me, is how to use the same strategy for multiple coins.
The strategy is mainly developed for Binance Futures trading not sure if possible to apply it to other Exchangers.
So I wanna setup alerting system for multiple coins to be connected to 3comma Bot or Finandy to execute a trade based on the setup parameter.
My questions are.
If I wanna use certain candle types like Hiken Ashi should that be included in the code or just select it in the chart and it will be read by the strategy automatically?
Should I include the coins in the script or I should select them one by one in the chart and then setup an alert per coin?
Should I create one alert per one coin per chart or I should have multiple charts per each coin to setup an alert?
Should the timeframe also be defined in the code or the chart can do the job?
Sorry for many questions, I'm trying to understand the process well.
For multiple coins, the easiest way is to attach your strategy to each and every coin on Tradingview you want to trade with. This way you can backtest each on their respective chart.
If you create a strategy for say BINANCE:BTCUSDT and think of using this strategy on different exchange, you can do it, but first I suggest test it on BINANCE:BTCPERP and see for yourself how the same strategy can show a wildly different result (even though BTCUSDT and BTCPERP should be moving the same).
For a complex solution you can create a single script that uses multiple securities, but you won't be able to backtest that with simple approach, you would have to write your own gain/loss calculator, and you are not there yet.
I was going down the same road, my suggestions are:
create an input for the coin you want to trade (that will go into an input variable)
abstract the alert message off of the strategy.entry() command, that is, construct the alert message in a way you can replace values with variables in it (like the above selected coin)
3Commas needs a Bot ID to start/stop a bot, abstract that off as well, and you will have a good boilerplate code you can reuse many times
as a good practice (stolen from Kubernetes) besides the human readable name, I give a 5 letter identifier to every one of my bots, for easy recognition
A few examples. The below will create a selector for a coin and the Bot ID that is used to trade that coin. The names like 'BIN:GMTPERP - osakr' are entirely my making, they act as a Key (for a key/value pair):
symbol_choser = input.string(title='Ticker symbol', defval='BTC-PERP - aktqw', options=[FTX_Multi, 'FTX:MOVE Single - pdikr', 'BIN:GMTPERP - osakr', 'BIN:GMTPERP - rkwif', 'BTC-PERP - aktqw', 'BTC-PERP - ikrtl', 'BTC-PERP - cbdwe', 'BTC-PERP', 'BAL-PERP', 'RUNE-PERP', 'Paper Multi - fjeur', 'Paper Single - ruafh'], group = 'Bot settings')
exchange_symbol = switch symbol_choser // if you use Single Pair bots on 3Commas, the Value should be an empty string
'BIN:GMTPERP - osakr' => 'USDT_GMTUSDT'
'BTC-PERP - cbdwe' => 'USD_BTC-PERP'
'Paper Multi - fjeur' => 'USDT_ADADOWN'
bot_id = switch symbol_choser
'BIN:GMTPERP - osakr' => '8941983'
'BTC-PERP - cbdwe' => '8669136'
'Paper Multi - fjeur' => '8246237'
And now you can combine the above parts into two Alerts, for starting/stopping the bot:
alertMessage_Enter = '{"message_type": "bot", "bot_id": ' + bot_id + ', "email_token": "12345678-4321-abcd-xyzq-132435465768", "delay_seconds": 0, "pair": "' + exchange_symbol + '"}'
alertMessage_Exit = '{"action": "close_at_market_price", "message_type": "bot", "bot_id": ' + bot_id + ', "email_token": "12345678-4321-abcd-xyzq-132435465768", "delay_seconds": 0, "pair": "' + exchange_symbol + '"}'
exchange_symbol is the proper exchange symbol you need to provide to your bot, you can get help on the 3Commas' bot page (they have pre-crafted the HTTP requests you need to use for certain actions).
bot_id is the ID of your Bot, that is straightforward.
The above solution does not handle Single coin bots, their trigger message has a different structure.
Whenever you can, use Multi coin bots as they can act as a Single bot with two exception:
if you have a long spanning strategy and when you start a bot, you should be already in a trade, you can manually start a Single bot, but you cannot start a Multi coin bot (as there is no way to provide the coin info on which to start the trade)
if you are trading a derivative like FTX's MOVE contracts and your script is attached to the underlying BTC Futures. MOVE contracts changes name every day (the date is in their name, like: BTC-MOVE-0523) so you would need delete an alert, update and reapply the alert every day, etc. Instead, if your script is on the BTC-PERP then you can use a Single coin bot which does not expect a coin name in the alert message so it will start/stop the Bot on whatever coin it is connected to, then you need to change the coin name every day only in the Bot settings and never touch the Alert.
To summarize on your questions:
Do not include chart type in code (that is not even an embeddable data), just apply your code to whatever chart you want to use. Hint: never use Heikin-Ashi for trading. You can, but you will pay for it dearly (everyone tries, even against warnings, no worries)
Set up them one-by-one, so you can backtest them
No, set the timeframe on the chart. Later, when you will be more experienced you will be able to abstract the current timeframe (whatever it is) away and write code that is timeframe-agnostic. But that's hard and make your code less readable.

Let Alexa ask the user a follow up question (NodeJS)

Background
I have an Intent that fetches some Data from an API. This data contains an array and I am iterating over the first 10 entries of said array and read the results back to the user. However the Array is almost always bigger than 10 entries. I am using Lambda for my backend and NodeJS as my language.
Note that I am just starting out on Alexa and this is my first skill.
What I want to archive is the following
When the user triggers the intent and the first 10 entries have been read to the user Alexa should ask "Do you want to hear the next 10 entries?" or something similar. The user should be able to reply with either yes or no. Then it should read the next entries aka. access the array again.
I am struggling with the Alexa implementation of this dialog.
What I have tried so far: I've stumbled across this post here, however I couldn't get it to work and I didn't find any other examples.
Any help or further pointers are appreciated.
That tutorial gets the concept right, but glosses over a few things.
1: Add the yes and no intents to your model. They're "built in" intents, but you have to add them to the model (and rebuild it).
2: Add your new intent handlers to the list in the .addRequestHandlers(...) function call near the bottom of the base skill template. This is often forgotten and is not mentioned in the tutorial.
3: Use const sessionAttributes = handlerInput.attributesManager.getSessionAttributes(); to get your stored session attributes object and assign it to a variable. Make changes to that object's properties, then save it with handlerInput.attributesManager.setSessionAttributes(sessionAttributes);
You can add any valid property name and the values can be a string, number, boolean, or object literal.
So assume your launch handler greets the customer and immediately reads the first 10 items, then asks if they'd like to hear 10 more. You might store sessionAttributes.num_heard = 10.
Both the YesIntent and LaunchIntent handlers should simply pass a num_heard value to a function that retrieves the next 10 items and feeds it back as a string for Alexa to speak.
You just increment sessionAttributes.num_heard by 10 each time that yes intent runs and then save it with handlerInput.attributesManager.setSessionAttributes(sessionAttributes).
What you need to do is something called "Paging".
Let's imagine that you have a stock of data. each page contains 10 entries.
page 1: 1-10, page 2: 11-20, page 3: 21-30 and so on.
When you fetching your data from DB you can set your limitations, In SQL it's implemented with LIMIT ,. But how you get those values based on the page index?
Well, a simple calculation can help you:
let page = 1 //Your identifier or page index. Managed by your client frontend.
let chunk = 10
let _start = page * chunk - (chunk - 1)
let _end = start + (chunk - 1)
Hope this helped you :)

Can i put Many Pictures links in dialogflow and send only one Randomly

I am new to dialogflow. I learned some things the previous month, but I am still searching for how to put a lot of pictures in intent and sending only one to the user, not all of them, and randomly, such as text responses as a kind of entertainment inside the Agent ...
Note :
I linked the client to Facebook Messenger and I want to send the photo there
Can i do this?
Assuming you're using Dialogflow-fulfillment library to respond to webhook requests this should do the trick.
You can store whatever type of response that you want to send in an array...
For example, I'll choose an array of plain text responses
const responses = [
"I didn't get that. Can you say it again?",
'I missed what you said. What was that?',
'Sorry, could you say that again?',
'Sorry, can you say that again?',
'Can you say that again?',
"Sorry, I didn't get that. Can you rephrase?",
'Sorry, what was that?',
'One more time?',
'What was that?',
'Say that one more time?',
"I didn't get that. Can you repeat?",
'I missed that, say that again?'
]
Given the array you can generate a random number between 0 (most programming languages index from 0) and the length of the array.
const index = Math.floor((Math.random() * responses.length) + 1)
In the above case, index is assigned to any number between 0 and 11. You can then pass this index into the array to randomly choose 1 value.
agent.add(responses[index])
You can take this concept and apply it to any response type you want.
Hope this does the trick for you!

Netsuite bug when creating customerdeposit record

Im trying to create a customer deposit record in Netsuite using suitescript 1.0.
The original code I had in place which had been working perfectly up until the 2016.2 release broke it.
The update broke it, in that it would override the value submitted in the payment field and instantly make it the full amount of the sales order from the sales order ID. Which is not what we need it to do.
Original Code
function createDeposit(request,response)
{
var record = nlapiCreateRecord('customerdeposit');
record.setFieldValue('salesorder','1260');
record.setFieldValue('customer','1170');
record.setFieldValue('payment','100');
record.setFieldValue('account','2');
record.setFieldValue('memo','this is a test');
deposit = nlapiSubmitRecord(record,true,false);
response.write(deposit);
}
After a reply on the Netsuite user group prompted me to use the {recordmode:'dynamic'} attributes I am getting a strange error..
Test Replacement Function which doesnt work
function createDeposit(request,response)
{
var record = nlapiCreateRecord('customerdeposit',{recordmode:'dynamic'});
record.setFieldValue('salesorder','1260');
record.setFieldValue('customer','1170');
record.setFieldValue('payment','100');
record.setFieldValue('account','2');
record.setFieldValue('memo','this is a test');
deposit = nlapiSubmitRecord(record,true,false);
response.write(deposit);
}
The error message Im getting now is
Invalid salesorder reference key 1260 for customer .
The thing I dont get is how it is now considered NULL, when the value is hardcoded into this test script after I apply the {recordmode:'dynamic'} value.
Ive tried a wide variety of things, but as I dont have Netsuite support, its proving to be something I simply cant figure out.
Any hints, suggestions would be greatly appreciated as Ive been on this for several days
When you use dynamic the order you set fields makes a difference. So when you set the sales order prior to setting the customer you are actually getting the error message "Invalid salesorder reference key 1260 for customer blank"
What I do is create the customer deposit like:
var depRec = nlapiCreateRecord('customerdeposit', {entity:soRec.getFieldValue('entity'), salesorder:soId});
also setting the undeposited funds flag seems to be required (but not always for some reason) so since you are supplying an account id also do this:
depRec.setFieldValue('undepfunds', 'F');

Turn Based Participant Timeout Date Always NULL

Have been working on a two-player turn based game that uses a custom UI for match management. Considering restricting the app to iOS 6+ in order to use player timeouts. I would like to show the user the remaining amount of time to move, but the participant.timeoutDate is always null? Per the WWDC 2012 video (that says the timeout won't apply to the last participant in nextParticipants), I pass an array with two entries (opponent at index 0 and local player at index 1) when calling endTurnWithNextParticipants:turnTimeout:matchData:completionHandler: to take a turn. I've tried both GKTurnTimeoutDefault and various integer literals ... no luck ... always seems to be null. The player's last turn date works fine.
On the subject of player timeouts ... after I get them working, how is this delivered? I see GKTurnBasedMatchOutcomeTimeExpired ... does this come in a turn event?
From Apple's developer forum
Elian Gidoni -
+1
The doc should be:
timeoutDate
The date and time when the participant’s turn timed out. (read-only)

Resources