When getting tweet information using the twitter API, the returned text or full_text field has a URL appended at the end of the text. For example:
"full_text": "Just another Extended Tweet with more than 140 characters, generated as a documentation example, showing that [\"truncated\": true] and the presence of an \"extended_tweet\" object with complete text and \"entities\" #documentation #parsingJSON #GeoTagged https://twitter.com/FloodSocial/status/994633657141813248"
https://twitter.com/FloodSocial/status/994633657141813248 is appended at the end(The appended url is acutally a shortened url but stackoverflow does not allow shortened url in the body so I just replace it with the full URL). Why does the API add this and is there a way to get the text without the added URL?
Are you using the correct twitter gem? using gem install twitter and setting up a client according to the docs, you should be able to just get the tweet/status by it's ID. But whatever example you are using doesn't show how you got the full text
text = client.status('994633657141813248').text
=>"Just another Extended Tweet with more than 140 characters, generated as a documentation example, showing that https://twitter.com/FloodSocial/status/994633657141813248"
The url is truncated as a plain string so not sure what you even do to get the string you formulated.
But if you have some long string somehow with the url embedded, you could do
text.split(/\shttp?s/).first
That looks like a quote Tweet where the original Tweet URL is included?
[edit - I was wrong with the above statement]
I see what is happening. The original Tweet links to an image on Twitter (https://twitter.com/FloodSocial/status/994633657141813248/photo/1, via a shortened tco link). Twitter hides the image URL in the rendered Tweet, but returns it in the body of the text. That's the expected behaviour in this case. You can also see the link parsed out in the extended_entities segment of the Tweet data, as well as the image data itself in the same area of the Tweet. If you want to omit the URL from the text data, you'll need to trim it yourself.
Related
I need to download an envelope from docusign by populating the tab data in ruby on rails.
I have used get_combined_document_from_envelope but it does not seems to get all the data.
def method_name
output_pdf = docusign.get_combined_document_from_envelope(
envelope_id: document.external_key,
local_save_path: "docusign_docs/file_name.pdf",
return_stream: false
)
end
I need the output file to have all the tabs populated.
The pdf would have the data inside the document as part of the completed doc (assuming it's visible). If you want to get the data downloaded separately, you would need to use API calls to get the envelope and get the tabs information. see this https://developers.docusign.com/esign-rest-api/guides/features/tabs
I have a URL that in the browser shows like this https://localhost:3000/location#valueIwant=1234.
I am trying to get access to the valueIwant value but all of the items I try ctx.request.path, ctx.request.href, etc but all seem to not have the values after #. How do I parse this part of the url.
Also this is coming from a redirect.
Everything after the # is not sent to the server. The purpose of the fragment is to create a link to a specific subsection of a page.
If you want to send specific parameters to the server, the right way to do it is to use the query part (everything after ?), not the fragment part. This is by design.
When appending ?__a=1 to a page on Instagram it is possible to view the JSON, as in this link:
https://www.instagram.com/explore/tags/malta/?__a=1.
This response contains an end_cursor field that references the last object in the response. The format of this field is: "J0HWJ-mOAAAAF0HWJ-hGgAAAFiYA.
Does anyone have a clue on how I can find out what information was encoded inside the string?
Building a small app and would like to return all a users favorited tweets. This is easy enough to do with the twitter gem. I would then like to further filter the returned results by only displaying the favorited tweets that contain a URL within the body.
Now as I understand it Using the the twitter gem running Twitter.favorites will return a json of all the favorited tweets. Now within each of the individual tweets it returns a entity property that contains a URL hash this will be empty if no URL is present in the tweet and a URL if one is present.
How would I implement a check to say if the URL is present then display tweet. I'm a noob with json and Apis.
I never used the twitter gem, but since the question remains unanswered for a couple of hours, I’ll try to do my best.
First of all the gem seems to return Array<Twitter::Tweet> rather than raw json. So you only need to filter the array:
favs_with_urls = Twitter.favorites.reject { |r| r.urls.empty }
The latter should do the trick.
BTW, if you for some reason need to parse json to a hash:
require 'json'
c = JSON.load(raw_json)
How would you use Ruby to open a website and do a search in the search field and then parse the results? For example if I entered something into a search engine and then parsed the results page. I know how to use Nokogiri to find the webpage and open it. I am lost on how to input into the search field and moving forward to the results. Also on the page that I am actually searching I have to click on enter, I can't simply hit enter to move forward. Thank you so much for your help.
Use Mechanize - a library used for automating interaction with websites.
Something like mechanize will work, but interacting with the front end UI code is always going to be slower and more problematic than making requests directly against the back end.
Your best bet would be to look at the request that is being made to the server (probably a HTTP GET or POST request with some associated params). You can do this with firebug or Fiddler 2 for windows. Then, once you know the parameters that the server will accept, just make the request yourself.
For example, if you were doing this with the duckduckgo.com search engine, you could either get mechanize to go to duckduckgo.com, input text into the search box, and click submit, or you could just create a GET request to http://www.duckduckgo.com?q=search_term_here.
You can use Mechanize for something like this but it might be overkill. I would take a look at RestClient, especially if you don't need to manage cookies.
Edit:
If you can determine the specific URL that the form submits to, say for example 'example.com/search'; and you knew the request was a POST (which it usually is if you are submitting a form) you could construct something like this with mechanize:
agent = Mechanize.new
agent.post 'http://example.com/search', {
"_id0:Number" => string_to_search_for,
"_id0:submitButton" => "Enter"
}
Notice how the 'name' attribute of a form element becomes a key for the post and the 'value' element becomes the value. The 'input' element gets the value directly from the text you would have entered. This gets transformed into a request and submitted to the server when you push the submit button (of course in this case you are making the request directly). The result of the post should be some HTML that you can parse for the info you need.