{"id":1874,"date":"2019-02-27T08:00:00","date_gmt":"2019-02-27T06:00:00","guid":{"rendered":"http:\/\/racov.ro\/?p=1874"},"modified":"2019-12-22T09:57:51","modified_gmt":"2019-12-22T07:57:51","slug":"nasa-astronomy-picture-of-the-day-widget","status":"publish","type":"post","link":"https:\/\/racov.ro\/index.php\/2019\/02\/27\/nasa-astronomy-picture-of-the-day-widget\/","title":{"rendered":"NASA Astronomy Picture Of The Day Widget"},"content":{"rendered":"<p>Am creat un widget care s\u0103 afi\u0219eze <a href=\"https:\/\/apod.nasa.gov\/apod\/astropix.html\" target=\"_blank\" rel=\"noopener noreferrer\">imaginea zilei<\/a> de la NASA.<br \/>\nDe fapt e un script care ruleaz\u0103 \u00een orice interpretor HTML.<\/p>\n<p>Pentru cine se gr\u0103be\u0219te, textul HTML e urm\u0103torul.<\/p>\n<p><span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;!DOCTYPE html&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;html&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;head&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;meta charset=&#8221;utf-8&#8243;&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;script src=&#8221;https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.11.3\/jquery.min.js&#8221;&gt;&lt;\/script&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;title&gt;MASA APOD&lt;\/title&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;\/head&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;body&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;script&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">var url = &#8220;https:\/\/api.nasa.gov\/planetary\/apod?api_key=NNKOjkoul8n1CH18TWA9gwngW1s1SmjESPjNoUFo&#8221;;<\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">$.ajax({<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">url: url,<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">success: function(result){<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">if(&#8220;copyright&#8221; in result) {<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">$(&#8220;#copyright&#8221;).text(&#8220;Image Credits: &#8221; + result.copyright);<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">}<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">else {<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">$(&#8220;#copyright&#8221;).text(&#8220;Image Credits: &#8221; + &#8220;Public Domain&#8221;);<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">}<\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">if(result.media_type == &#8220;video&#8221;) {<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">$(&#8220;#apod_img_id&#8221;).css(&#8220;display&#8221;, &#8220;none&#8221;); <\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">$(&#8220;#apod_vid_id&#8221;).attr(&#8220;src&#8221;, result.url);<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">}<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">else {<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">$(&#8220;#apod_vid_id&#8221;).css(&#8220;display&#8221;, &#8220;none&#8221;); <\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">$(&#8220;#apod_img_id&#8221;).attr(&#8220;src&#8221;, result.url);<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">}<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">$(&#8220;#reqObject&#8221;).text(url);<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">$(&#8220;#returnObject&#8221;).text(JSON.stringify(result, null, 4)); <\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">$(&#8220;#apod_explaination&#8221;).text(result.explanation);<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">$(&#8220;#apod_title&#8221;).text(result.title);<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">}<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">});<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;\/script&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;h3 id=&#8221;apod_title&#8221;&gt;&lt;\/h3&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;img id=&#8221;apod_img_id&#8221; width=&#8221;300px&#8221;\/&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;iframe id=&#8221;apod_vid_id&#8221; type=&#8221;text\/html&#8221; width=&#8221;640&#8243; height=&#8221;385&#8243; frameborder=&#8221;0&#8243;&gt;&lt;\/iframe&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;p id=&#8221;copyright&#8221;&gt;&lt;\/p&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;a href=&#8221;https:\/\/apod.nasa.gov\/apod\/astropix.html&#8221;&gt;More to read&#8230;&lt;\/a&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;br\/&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;\/body&gt;<\/span><br \/>\n<span style=\"font-family: courier new,courier,monospace; font-size: 10pt;\">&lt;\/html&gt;<\/span><\/p>\n<p>Amatorismul meu \u00een materie de HTML \u0219i Java a \u00eenfr\u00e2nt din nou, ca \u0219i \u00een articolul <a href=\"http:\/\/racov.ro\/index.php\/2017\/02\/17\/ceas-cu-termometru-pe-net\/\" target=\"_blank\" rel=\"noopener noreferrer\">acesta<\/a>, dar nu am avut \u00eencotro. Am c\u0103utat tot internetul pentru un widget <em>original<\/em>, f\u0103cut de al\u021bii, dar nu exist\u0103. Cele 2 din wordpress nu func\u021bioneaz\u0103. Au mers odat\u0103, dar s-au oprit. Nu mai merg.<\/p>\n<p>Sursa de energie am g\u0103sit-o tot pe site-ul NASA, la <a href=\"https:\/\/api.nasa.gov\/index.html\" target=\"_blank\" rel=\"noopener noreferrer\">open API<\/a>, \u0219i\u00a0cu pu\u021bin ajutor \u0219i mult <em>trial and error<\/em>, am pus laolalt\u0103 textul de mai sus.<br \/>\n<a href=\"https:\/\/api.nasa.gov\/index.html#live_example\" target=\"_blank\" rel=\"noopener noreferrer\">Aici<\/a> este punctul de plecare. Scriptul folose\u0219te un API KEY demo, dar te rog s\u0103 ceri unul personalizat de <a href=\"https:\/\/api.nasa.gov\/index.html#apply-for-an-api-key\" target=\"_blank\" rel=\"noopener noreferrer\">aici<\/a> \u0219i s\u0103 \u00eel schimbi. \u00cenlocuirea se face \u00een linia aceasta:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1879\" data-permalink=\"https:\/\/racov.ro\/index.php\/2019\/02\/27\/nasa-astronomy-picture-of-the-day-widget\/untitled-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/racov.ro\/wp-content\/uploads\/2019\/02\/Untitled.png?fit=557%2C68&amp;ssl=1\" data-orig-size=\"557,68\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Untitled\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/racov.ro\/wp-content\/uploads\/2019\/02\/Untitled.png?fit=557%2C68&amp;ssl=1\" class=\"alignnone wp-image-1879 size-full\" src=\"https:\/\/i0.wp.com\/racov.ro\/wp-content\/uploads\/2019\/02\/Untitled.png?resize=557%2C68\" alt=\"\" width=\"557\" height=\"68\" srcset=\"https:\/\/i0.wp.com\/racov.ro\/wp-content\/uploads\/2019\/02\/Untitled.png?w=557&amp;ssl=1 557w, https:\/\/i0.wp.com\/racov.ro\/wp-content\/uploads\/2019\/02\/Untitled.png?resize=300%2C37&amp;ssl=1 300w\" sizes=\"auto, (max-width: 557px) 100vw, 557px\" \/><\/p>\n<p>Finalul arat\u0103 ca \u00een widgetul din dreapta, iar imaginea se schimb\u0103 la fiecare interogare, conform cu cea publicat\u0103 de NASA \u00een ziua respectiv\u0103.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Am creat un widget care s\u0103 afi\u0219eze imaginea zilei de la NASA. De fapt e un script care ruleaz\u0103 \u00een<\/p>\n","protected":false},"author":1,"featured_media":1875,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7],"tags":[],"class_list":["post-1874","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-7"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/racov.ro\/wp-content\/uploads\/2019\/02\/feat.png?fit=700%2C350&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p75FkB-ue","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/racov.ro\/index.php\/wp-json\/wp\/v2\/posts\/1874","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/racov.ro\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/racov.ro\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/racov.ro\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/racov.ro\/index.php\/wp-json\/wp\/v2\/comments?post=1874"}],"version-history":[{"count":8,"href":"https:\/\/racov.ro\/index.php\/wp-json\/wp\/v2\/posts\/1874\/revisions"}],"predecessor-version":[{"id":2218,"href":"https:\/\/racov.ro\/index.php\/wp-json\/wp\/v2\/posts\/1874\/revisions\/2218"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/racov.ro\/index.php\/wp-json\/wp\/v2\/media\/1875"}],"wp:attachment":[{"href":"https:\/\/racov.ro\/index.php\/wp-json\/wp\/v2\/media?parent=1874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/racov.ro\/index.php\/wp-json\/wp\/v2\/categories?post=1874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/racov.ro\/index.php\/wp-json\/wp\/v2\/tags?post=1874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}