I am trying to replicate the example shown in this SO question, and I am stumbling in what looks like a Twython bug, appreciate any insight
Here's the code:
status_id = <some_status_id>
response = twitter.get_retweets(status_id, 100)
which results in the following error
TypeError: get_retweets() takes 1 positional argument but 3 were given
I tried to run without arguments as in
response = twitter.get_retweets()
and then I get an error from Twitter saying
twython.exceptions.TwythonError: Twitter API returned a 404 (Not Found), Sorry, that page does not exist
Is this a bug?
Solved, the status_id must be passed as a named parameter
status_id = <some_status_id>
response = twitter.get_retweets(id=status_id) # 100 is already the max available
Related
In code segment, I saw it uses windows function as follows.
test_by_time = Window.partitionBy("testId").orderBy("Time")
My question is that how to view the results of the windows.partitonby, i.e., test_by_time here. I tried to use test_by_time.show(), but the error AttributeError: 'WindowSpec' object has no attribute` 'show' is given.
so recently im trying to make a website scraper
its mostly done all im just trying to do is just take input from user
and add it in url i am doing it like this
namer = input('Enter name: ')
state = input('Enter state: ')
driver.get("https://www.example.com/people-search/"+ name,"/?state="+ state)
but when i try to run this code i am getting below error :
TypeError: get() takes 2 positional arguments but 3 were given
i have tried some answers that were here posted on stackoverflow
but none of them worked
You can join string like
driver.get("https://www.example.com/people-search/"+namer+"/?state="+ state)
My code accesses a light sensor via a python request:
address = 'https://api.particle.io/v1/devices/my_device_id/analogvalue'
headers = {'Authorization':'Bearer {0}'.format(access_token)}
vals = requests.get(address, headers=headers)
The code returns the following values:
{"cmd":"VarReturn","name":"analogvalue","result":171,"coreInfo":{"last_app":"","last_heard":"2019-06-13T21:55:57.387Z","connected":true,"last_handshake_at":"2019-06-13T20:51:02.691Z","deviceID":"my_device_id","product_id":6}}
Python tells me that this is a 'requests.models.Response' class and not a dictionary like I thought.
When I try to access the 'result' value, I get error messages. Here are the various ways I have tried along with their error messages.
print(vals[2])
TypeError: 'Response' object does not support indexing
print(vals['result'])
TypeError: 'Response' object is not subscriptable
print(vals[2].json())
TypeError: 'Response' object does not support indexing
print(vals['result'].json())
TypeError: 'Response' object is not subscriptable
I got the last two approaches (.json) from a answer here on stack overflow.
Can anyone tell me how to access this result value or am I going to be forced to use regular expression?
EDIT: With help from Sebastien D I added the following and was able to get the result I was looking for.
import json
new_vals = json.loads(vals.content)
print(new_vals['result'])
Just do :
import json
### your code ###
json.loads(vals.content)
I have function for newspaper3k which extract summary for given url. Given as :-
def article_summary(row):
url = row
article = Article(url)
article.download()
article.parse()
article.nlp()
text = article.summary
return text
I have pandas dataframe with column named as url
url
https://www.xyssss.com/dddd
https://www.sbkaksbk.com/shshshs
https://www.ascbackkkc.com/asbbs
............
............
There is another function main_code() which runs perfectly fine and inside which Im using article_summary.I want to add both functions article_summary and main_code() into one function final_code.
Here is my code : 1st function as:-
def article_summary(row):
url = row
article = Article(url)
article.download()
article.parse()
article.nlp()
text = article.summary
return text
Here is 2nd Function
def main_code():
article_data['article']=article_data['url'].apply(article_summary)
return article_data['articles']
When I have done:
def final_code():
article_summary()
main_code()
But final_code() not giving any output it shows as TypeError: article_summary() missing 1 required positional argument: 'row'
Are those the actual URLs you're using? If so, they seem to be causing an ArticleException, I tested your code with some wikipedia pages and it works.
On that note, are you working with just one df? If not, it's probably a good idea to pass it as a variable to the function.
-----------------------------------Edit after comments----------------------------------------------------------------------
I think a tutorial on Python functions will be beneficial. That said, in regards to your specific question, calling a function the way you described it will make it run twice, which is not needed in this case. As I said earlier, you should pass the df as an argument to the function, here is a tutorial on global vs local variables and how to use them.
The error you're getting is because you should pass an argument 'row' to the function article_summary (please see functions tutorial).
I am trying to convert seconds in HH:MM:SS format. I am getting an error moment.duration is not a function.
var moment = require("moment-duration-format");
moment.duration(123, "seconds").format("hh:mm:ss");
The moment-duration-format plugin depends on moment, so you should import/require it first:
var moment = require("moment")
require("moment-duration-format");
moment.duration(123, "seconds").format("hh:mm:ss");
I tried both
import 'moment-duration-format';
and
require("moment-duration-format");
but it did not solve my problem and I was still getting TypeError: moment.duration(...).format is not a function so I took a look at https://www.npmjs.com/package/moment-duration-format to find how to correctly set it up and I found out that I have to call it and pass moment in order to make it work correctly.
import momentDurationFormatSetup from 'moment-duration-format';
momentDurationFormatSetup(moment);