Setting the Notebook to post Notes within in Evernote w/ RoR - ruby-on-rails

How do you make sure a Note is created in a specific NoteBook that is not the default?
In the client sample code that Evernote provides they show this
client = EvernoteOAuth::Client.new(token: authToken)
# List all of the notebooks in the user's account
note_store = client.note_store
notebooks = note_store.listNotebooks(authToken)
puts "Found #{notebooks.size} notebooks:"
defaultNotebook = notebooks.first
notebooks.each do |notebook|
puts " * #{notebook.name}"
end
puts
puts "Creating a new note in the default notebook: #{defaultNotebook.name}"
puts
But the variable defaultNotebook does not get used again. The note get's posted at the end with
createdNote = note_store.createNote(authToken, note)
I guess that in the demo the defaultNotebook is assumed for any notes that get posted.
There isn't a setNotebook method, but there is a getNotebook one. Which the code demo for that is as follows.
client = EvernoteOAuth::Client.new(token: authtoken)
note_store = client.note_store
# We can ignore the creation here
notebook = Evernote::EDAM::Type::Notebook.new
notebook.name = "Notebook 1402371893"
created_notebook = note_store.createNotebook(notebook)
# Here we see it is retrieved with the guid
note_store.getNotebook(created_notebook.guid)
So does the getNotebook method act as setting the notebook on the note_store instance which I can then create Notes within? I have a feeling it's that simple. I'll give it a try.
EDIT
Here are more details on the way I'm trying to implement the usage of setting the Notebook that receives the Notes:
client = EvernoteOAuth::Client.new( token: user.evernote_token )
noteStore = client.note_store
if user.evernote_notebook.length.zero?
notebook = Evernote::EDAM::Type::Notebook.new()
notebook.name = "MyBook"
user.update_attribute( :evernote_notebook,
noteStore.createNotebook( user.evernote_token, notebook ).guid )
else
noteStore.getNotebook( user.evernote_notebook )
end
createdNote = noteStore.createNote( user.evernote_token, note )
image.update_attribute( :evernote_guid, createdNote.guid )
The purpose is to know the Notebook is set and the Note will be placed there.
NOTE THIS CODE WORKS --BUT-- The Note's in the wrong folder. It's in default and not the one I selected.
Here's the working answer
note = Evernote::EDAM::Type::Note.new()
client = EvernoteOAuth::Client.new( token: user.evernote_token )
noteStore = client.note_store
if user.evernote_notebook.length.zero?
notebook = Evernote::EDAM::Type::Notebook.new()
notebook.name = "MyBook"
user.update_attribute( :evernote_notebook,
noteStore.createNotebook( user.evernote_token, notebook ).guid )
end
note.notebookGuid = user.evernote_notebook
createdNote = noteStore.createNote( user.evernote_token, note )
image.update_attribute( :evernote_guid, createdNote.guid )

How do you make sure a Note is created in a specific NoteBook that is not the default?
If you want to create a note in a specific notebook, just set the 'notebookGuid' attribute of the note.
note.notebookGuid = created_notebook.guid
If you don't explicitly set the notebookGuid attribute, the note will be created in the default notebook of the account.
The getNotebook method only retrieves the notebook you specified.

Related

How to get Twitter mentions id using academictwitteR package?

I am trying to create several network analyses from Twitter. To get the data, I used the academictwitteR package and their get_all_tweets command.
get_all_tweets(
users = c("LegaSalvini"),
start_tweets = "2007-01-01T00:00:00Z",
end_tweets = "2022-07-01T00:00:00Z",
file = "tweets_lega",
data_path = "tweetslega/",
bind_tweets = FALSE
)
## Binding JSON files into data.frame objects
tweets_bind_lega <- bind_tweets(data_path = "tweetslega/")
##Tyding
tweets_bind_lega_tidy <- bind_tweets(data_path = "tweetslega/", output_format = "tidy")
With this, I can easily access the ids for the creation of a retweet and reply network. However, the tidy format does not provide a tidy column for the mentions, instead it deletes them.
However, they are in my untidy df tweets_bind_lega , but stored as a list tweets_bind_afd$entities$mentions. Now I would like to somehow unnest this list and create a tidy df with a column that has contains the mentioned Twitter user ids.
Has anyone created a mention network with academictwitteR before and can help me out?
Thanks!

Can't preserve document core metadata (Created By, Modified By) when I import documents to SharePoint Document Library

I'm currently building a tool to migrate from a document management system to use SharePoint Online. The main challenge I'm facing is to preserve the details of document authors and creating time. I have checked bunch of of code online but I didn't get success with any of them.
Here are the approaches I used
SharePoint Rest API
Microsoft Graph API
CSOM (using console application)
Here is the code I have so far in CSOM but I'm still not able to update the Author field
li["Title"] = "Update from CSOM";
li["Created"] = DateTime.Now.AddYears(-5);
li["Author"] = author.Id;
li.UpdateOverwriteVersion();
clientContext.ExecuteQuery();
Any idea for how to do this, or if there is any other approach to achieve my goal?
The code works when I did test in my environment.
using (ClientContext context = new ClientContext("https://xxx.sharepoint.com/sites/lee"))
{
string s = "password";
SecureString passWord = new SecureString();
foreach (var c in s)
passWord.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials("admin#xxx.onmicrosoft.com", passWord);
var author = context.Web.EnsureUser("Lee#xxx.onmicrosoft.com");
context.Load(author);
context.ExecuteQuery();
var _List = context.Web.Lists.GetByTitle("List1");
var li = _List.GetItemById(1);
li["Title"] = "Update from CSOM";
li["Created"] = DateTime.Now.AddYears(-5);
li["Author"] = author.Id;
li.UpdateOverwriteVersion();
context.ExecuteQuery();
}
You will need to update the Author and Editor fields at the same time in order to update the CreatedBy field. If you wish to update additional fields at the same time you can. Using SystemUpdate() does not update the Modified date whereas Update() does update the Modified date. See abbreviated sample below.
FieldUserValue userValue = new FieldUserValue();
User newUser = cc.Web.EnsureUser("newAuthor#xxx.onmicrosoft.com");
cc.Load(newUser);
cc.ExecuteQuery();
userValue.LookupId = newUser.Id;
item["Author"] = userValue;
item["Editor"] = userValue;
item.SystemUpdate();
cc.ExecuteQuery();

Can't Identify Proper CSS Selector to Scrape with Mechanize

I have built a web scraper that is successfully pulling almost everything I need out of the web page I'm looking at. The goal is to pull the URL for a particular image associated with all the coffees found at a particular URL.
The rake task I have defined to complete the scraping is as follows:
mechanize = Mechanize.new
mechanize.get(url) do |page|
page.links_with(:href => /products/).each do |link|
coffee_page = link.click
bean = Bean.new
bean.acidity = coffee_page.css('[data-id="acidity"]').text.strip.gsub("acidity ","")
bean.elevation = coffee_page.css('[data-id="elevation"]').text.strip.gsub("elevation ","")
bean.roaster_id = "2"
bean.harvest_season = coffee_page.css('[data-id="harvest"]').text.strip.gsub("harvest ","")
bean.price = coffee_page.css('.price-wrap').text.gsub("$","")
bean.roast_profile = coffee_page.css('[data-id="roast"]').text.strip.gsub("roast ","")
bean.processing_type = coffee_page.css('[data-id="process"]').text.strip.gsub("process ","")
bean.cultivar = coffee_page.css('[data-id="cultivar"]').text.strip.gsub("cultivar ","")
bean.flavor_profiles = coffee_page.css('.price-wrap+ p').text.strip
bean.country_of_origin = coffee_page.css('#pdp-order h1').text.strip
bean.image_url = coffee_page.css('img data-featured-product-image').attr('src')
if bean.country_of_origin == "Origin Set" || bean.country_of_origin == "Gift Card (online use only)"
bean.destroy
else
ap bean
end
end
end
Now the information I need is all on the page, and I'm looking for the image URL that is found like the below, but for all the individual coffee_pages at the source page. It needs to be generic enough to pull this picture source but nothing else. I've tried a number of different css selectors but everything pulls either nil or blank.
<img src="//cdn.shopify.com/s/files/1/2220/0129/products/ceremony-product-gummy-bears_480x480.jpg?v=1551455589" alt="Burundi Kiryama" data-product-featured-image style="display:none">
The coffee_page I'm on is here: https://shop.ceremonycoffee.com/products/burundi-kiryama
You need to change
bean.image_url = coffee_page.css('img data-featured-product-image').attr('src')
to
bean.image_url = coffee_page.css('#mobile-only>img').attr('src')
If you can, always use nearby identifiers to locate the element you want to access.

Azure SDK Ruby Set Container ACL

I'm using https://github.com/Azure/azure-sdk-for-ruby in my Rails application. I need to set the container policy but I don't know how to create a Signed Identifier instance for the set_container_acl method.
The comments say to pass in an array of "Azure::Entity::SignedIdentifier instances" but when I try to create an instance I get "uninitialized constant Azure::Storage::Entity". Scoured the net/documentation can't find anything about it.
After digging around in the azure gem files I was able to find a signed identifier file in the service directory. It's not loaded with azure for some reason so you have to require it.
require 'azure'
require 'azure/service/signed_identifier'
def some_method
# Some code here. Create blobs instance.
# blobs = Azure::Blob::BlobService.new
sas = Azure::Service::SignedIdentifier.new
sas.id = identifier
policy = sas.access_policy
policy.start = (Time.now - 5 * 60).utc.iso8601
policy.expiry = (Time.now + 1.years).utc.iso8601
policy.permission = "r"
identifiers = [sas]
options = { timeout: 60, signed_identifiers: identifiers }
container, signed = blobs.set_container_acl(container_name, "", options)
end

Saving images with Carrierwave inside a ruby worker

I'm trying to write a method to store an image from a given url, inside a ruby worker. It comes along my Rails app in which I display the object image.
Here is what I've come up with :
def store(url)
#object = Object.find(1)
#object[:image] = CarrierWave::Uploader.store!(image_url)
end
It doesn't seem to work at all.
Any clues?
Is there another way around?
[EDIT]
Here is the current situation :
def store
#object = Object.find(1)
my_uploader = ImageUploader.new
image = open("http://twitpic.com/show/iphone/xxxx.jpg")
# or for a local file:
image = File.open(Rails.root.join('xxxx.png'))
#object[:image] = my_uploader.store!(image)
#object.save!
end
The filename in the [:image] attibute is still wrong. It gives "[:store_versions!]". How do I get the filename right?
[EDIT2]
Got the filename right by adding #artwork[:image] = my_uploader.filename before save.
But #object = Object.find(1) won't work. How do I access the Object class, which is inside my rails app, from the worker?
#object.image.store!(image) finally did the job!
You'll want to create a new uploader object and point it to your file
image = File.open(Rails.root.join('path', 'to', 'file.png'))
#object[:image] = YourUploader.new(image)

Resources