Setting Google Photos date - google-api

I uploaded many photos with no EXIF data, but with their date in the name. Google Photos used upload date to sort them. I'd like to use the date in their name to modify them.
So far I tried to use Drive API to change modification date, I can change it but it is not used. I also tried to modify imageMediaMetadata.date, but it seems to be read-only to me.
Code:
function myFunction() {
var files = DriveApp.getFilesByName("IMG-20150402-WA0002_1.jpg")
while (files.hasNext()) {
var file = files.next();
var name = file.getName().toUpperCase();
if (name.indexOf("-WA") > -1) {
if (name.indexOf("IMG-20") == 0 || name.indexOf("VID-20") == 0) {
var y = name.substr(4, 4);
var m = name.substr(8, 2);
var d = name.substr(10, 2);
var file2 = Drive.Files.get(file.getId());
file2.imageMediaMetadata.date = y+"-"+m+"-"+d+"T12:00:00.000Z";
var file3 = Drive.Files.patch(file2, file.getId());
Logger.log(name + " no ok " + file3.imageMediaMetadata.date); // same as file2
}
}
}
I could delete them, modify the original files and re-upload, but before that I'd like to be sure there is no other way.
Thank you.

Perhaps you could programmatically write an EXIF header to the files?
I would also be looking for a convenient way to supply photo date when uploading old photos using the new-ish Google Photos API. My photos do not necessarily have EXIF data; I tried setting the creation/last modified date on one of my JPEGs on my MacOS machines disk, then manually uploading it via the Google Photos web interface and the date of of the JPEG file on local disk becomes the photo's date in Google Photos, as expected. The file has no EXIF data and if did, it would not contain that same date, so apparently the google photos web uploader respects the local filesystem date for the photo.
I then tried to sniff the traffic using Charles Proxy, but apparently the web interface does not use the Google Photos API same way that us external developers would -- it doesnt POST to https://photoslibrary.googleapis.com/v1/uploads or so it seems. So I couldn't reverse engineer that process. Also I couldn't see where the file creation date was passed in.
What would be great is to have a HTTP header in the upload POST request to set this date. I dont see batchCreate (https://developers.google.com/photos/library/reference/rest/v1/mediaItems/batchCreate) method having any means of setting this.

Related

Google sheets IMPORTXML fails for ASX data

I am trying to extract the "Forward Dividend & Yield" value from https://finance.yahoo.com/ for multiple companies in different markets, into Google Sheets.
This is successful:
=IMPORTXML("https://finance.yahoo.com/quote/WBS", "//*[#id='quote-summary']/div[2]/table/tbody/tr[6]/td[2]")
But this fails with #N/A:
=IMPORTXML("https://finance.yahoo.com/quote/CBA.AX", "//*[#id='quote-summary']/div[2]/table/tbody/tr[6]/td[2]")
I cannot work out what needs to be different for ASX ticker codes, why does CBA.AX cause a problem?
Huge thanks for any help
When I tested the formula of =IMPORTXML("https://finance.yahoo.com/quote/CBA.AX", "//*"), an error of Error Resource at url not found. occurred. I thought that this might be the reason of your issue.
But, fortunately, when I try to retrieve the HTML from the same URL using Google Apps Script, the HTML could be retrieved. So, in this answer, I would like to propose to retrieve the value using the custom function created by Google Apps Script. The sample script is as follows.
Sample script:
Please copy and paste the following script to the script editor of Google Spreadsheet and save it. And, please put a formula of =SAMPLE("https://finance.yahoo.com/quote/CBA.AX") to a cell. By this, the value is retrieved.
function SAMPLE(url) {
const res = UrlFetchApp.fetch(url).getContentText().match(/DIVIDEND_AND_YIELD-value.+?>(.+?)</);
return res && res.length > 1 ? res[1] : "No value";
}
Result:
When above script is used, the following result is obtained.
Note:
When this script is used, you can also use =SAMPLE("https://finance.yahoo.com/quote/WBS").
In this case, when the HTML structure of the URL is changed, this script might not be able to be used. I think that this situation is the same with IMPORTXML and the xpath. So please be careful this.
References:
Custom Functions in Google Sheets
Class UrlFetchApp
An other solution is to decode the json contained in the source of the web page. Of course you can't use importxml since the web page is built on your side by javascript and not on server's side. You can access data by this way and get a lot of informations
var source = UrlFetchApp.fetch(url).getContentText()
var jsonString = source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}'
i.e. for what you are looking for you can use
function trailingAnnualDividendRate(){
var url='https://finance.yahoo.com/quote/CBA.AX'
var source = UrlFetchApp.fetch(url).getContentText()
var jsonString = source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}'
var data = JSON.parse(jsonString)
var dividendRate = data.context.dispatcher.stores.QuoteSummaryStore.summaryDetail.trailingAnnualDividendRate.raw
Logger.log(dividendRate)
}

Add download to Firefox via Firefox extension

This is my first Firefox extension which I'm developing with addon-builder [builder.addons.mozilla.org/] .
My question is simple but after trying many things, for many days, I'm unable to get results.
I want to know: How to add a file download to Firefox downloader??
I've a url like: http:// example.com/file.zip and a file location like: D:\myFolder.
I want to add this download via my firefox extension.
The things which I've searched are:
https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIWebBrowserPersist#saveURI%28%29
https://developer.mozilla.org/en-US/docs/Code_snippets/Downloading_Files
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
const WebBrowserPersist = Components.Constructor("#mozilla.org/embedding/browser/nsWebBrowserPersist;1",
"nsIWebBrowserPersist");
var persist = WebBrowserPersist();
var targetFile = Services.dirsvc.get("Desk", Ci.nsIFile);
targetFile.append("file.bin");
// Obtain the privacy context of the browser window that the URL
// we are downloading comes from. If, and only if, the URL is not
// related to a window, null should be used instead.
var privacy = PrivateBrowsingUtils.privacyContextFromWindow(urlSourceWindow);
persist.persistFlags = persist.PERSIST_FLAGS_FROM_CACHE
| persist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
persist.saveURI(uriToSave, null, null, null, "", targetFile, privacy);
Can you just gimme a start from where I should get the easiest possible download function.
Components.utils.import("resource://gre/modules/Services.jsm");
var {downloads}=Services;
downloads.addDownload(/*parameters*/); //see documentation for parameters.
Documentation for addDownload: nsIDownloadManager#addDownload()
Documentation and directory for the wide range of services provided by Services.jsm: Services.jsm

How to download a jpg from web to project folder in MVC3?

Hello everyone I would like to ask How can I download .jpg file from web to my project's folder which I have created "uploads" ?
I'm trying to downlaod youtube thumbnail image to my" uploads" folder.
My controller:
var fileName = Path.GetFileName(http://img.youtube.com/vi/RUgd_GDPhYk/1.jpg);
var path = Path.Combine(Server.MapPath("~/uploads/"), fileName);
file.SaveAs(path);
Take a look at System.Net.WebClient, a .NET class which allows you to make requests for resources via HTTP.
http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.100).aspx
Checked example provided.
var client = new System.Net.WebClient();
var uri = "http://img.youtube.com/vi/RUgd_GDPhYk/1.jpg";
// Here, we're just using the same filename as the resource we're after.
// You may wish to change this to include extra stuff because you'll
// inevitably run into a naming clash - especially with stuff like 1.jpg
var targetFilename = Path.GetFileName(uri);
client.DownloadFile(uri,
Path.Combine(Server.MapPath("~/uploads"), targetFilename));

count image hash(md5) in adobe air

I use HTML+JAVASCRITP+CSS develop desktop software in adobe air platform
I download md5.js that count md5 value as same php md5 value
air.filestream function read location of file and send to md5.js to count hash ,normal file(js,php,css,txt) can count as same php md5 value, but count image file get wrroy hash,the image isn't change.
var fileStream = new air.FileStream();
var target = new air.File(file.nativePath);
fileStream.open(target , air.FileMode.READ);
var str = fileStream.readMultiByte(target.size,'utf-8'); alert(window.md5(str));
You should use this library that does reading binary data.
Then, unzip the swc and get the swf file to a lib folder in your app path.
You must check the xml file to get the qualified name of the md5 function you want to use
(.by.blooddy.crypto.MD5.hashBytes(data) )
Add an script include line on the html header
<script src="lib/library.swf" type="application/x-shockwave-flash"></script>
and you can use the function trought the window.runtime object:
hash = window.runtime.by.blooddy.crypto.MD5.hashBytes(data);
and this hash will be the same you can get with a md5 in php.
By the way you must read the file using readBytes instead of readMultiByte.
adobe link (Using ActionScript libraries within an HTML page)

How to upload image in Windows Azure platform: best approach

Ihave a register form with an Image Upload and it doesn't work when I upload my package application in my Windows Azure server.
The image address in the server looks like this:
F:\sitesroot\0\Uploads\Users\9259826_2121813246965_1294840438_2490950_6619588_n.jpg
If I had this image url like this, with it's relative path:
http://dealma.cloudapp.net/Uploads/Users/9259826_2121813246965_1294840438_2490950_6619588_n.jpg
I would already solve the problem.
The current code I'm using to upload is this:
if (userImg != null && userImg.ContentLength > 0)
{
try
{
var fileName = Url.Encode(userImg.FileName);
//no overwrite files
var pathToCheck = Server.MapPath("~/Uploads/Users/" + fileName);
var savePath = Server.MapPath("~/Uploads/Users/");
var tempfileName = fileName;
int counter = 2;
while (System.IO.File.Exists(pathToCheck))
{
tempfileName = counter.ToString() + fileName;
pathToCheck = savePath + tempfileName;
counter++;
}
fileName = tempfileName;
var finalImg = Path.Combine(savePath, fileName);
userImg.SaveAs(finalImg);
//Img name
userSet.Picture = finalImg;
userSet.Thumbnail = finalImg;
}
catch (Exception ex)
{
Response.Write("Não foi possível fazer upload do arquivo: " + ex.Message);
}
}
Does anyone knows how to solve this problem?
As corvus stated, you are writing to "local storage" which is volatile and not shared across multiple instances of your virtual machine.
Blob storage lets you store arbitrary files, images, etc. Each item gets stored in its own blob. You also have the notion of a "container" - think of it as a top-level directory folder. There are no nested containers, but you can emulate them with path characters in the name (skip this for now, as you need a quick solution).
If you download the Windows Azure Platform Training Kit and look at the lab "Introduction to Cloud Services", it shows a Guestbook application, where photos are uploaded to blob storage. You will see how to set up a storage account, as well as writing the code to push your file to a blob instead of the local file system. Here's a snippet from the sample:
Initialize blob client, and set up container to store your files:
var storageAccount =
CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
// create blob container for images
blobStorage = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobStorage.GetContainerReference("uploads");
container.CreateIfNotExist();
Now, in your upload handler, you'd write to a blob instead of local file system:
string uniqueBlobName = string.Format("uploads/image_{0}{1}",
Guid.NewGuid(), Path.GetExtension(UserImg.FileName));
CloudBlockBlob blob = blobStorage.GetBlockBlobReference(uniqueBlobName);
blob.Properties.ContentType = UserImg.PostedFile.ContentType;
// note: there are several blob upload methods -
// choose the best one that fits your app
blob.UploadFromStream(UserImg.FileContent);
You'll see the full working sample once you download the Platform Training Kit.
You are trying to save the image to the virtual machine where web role handling your request resides.
Probably there is more than one web role instance in your application. So, the file gets saved on one machine, but next request is served by another web role and virtual machine that doesn't have this file.
So, good idea is to save all data that needs to be accessible from any web role, to blobs. If you have some static data, you can put this data into package with your web role. All other data should reside in blobs.
If you don't want to modify the code of your application, you can map a part of blob storage as another hard drive to every instance of your web role. In this case, you just need to write received data to this mapped disk. The results will be accessible from any web role.

Resources