{"id":23591,"date":"2024-04-17T11:08:26","date_gmt":"2024-04-17T09:08:26","guid":{"rendered":"https:\/\/www.wjst.de\/blog\/?p=23591"},"modified":"2024-04-17T11:12:58","modified_gmt":"2024-04-17T09:12:58","slug":"from-start-to-finish-programming-with-chatgpt-in-60s","status":"publish","type":"post","link":"https:\/\/www.wjst.de\/blog\/sciencesurf\/2024\/04\/from-start-to-finish-programming-with-chatgpt-in-60s\/","title":{"rendered":"From start to finish programming with ChatGPT in 60s"},"content":{"rendered":"<blockquote><p>Create a PHP script that can read a CSV in the form start_date, end_date, event and output as ICS file<\/p><\/blockquote>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction convertDate($date)\r\n{\r\n    $dateTime = DateTime::createFromFormat(&#039;m\/d\/Y&#039;, $date);\r\n    if ($dateTime === false) {\r\n        return false; \/\/ Return false if date parsing fails\r\n    }\r\n    return $dateTime-&gt;format(&#039;Ymd&#039;);\r\n}\r\n\r\n\/\/ Function to escape special characters in text\r\nfunction escapeText($text)\r\n{\r\n    return str_replace(&#x5B;&quot;\\n&quot;, &quot;\\r&quot;, &quot;,&quot;, &quot;;&quot;], &#x5B;&#039;\\n&#039;, &#039;\\r&#039;, &#039;\\,&#039;, &#039;\\;&#039;], $text);\r\n}\r\n\r\n\/\/ Read CSV file\r\n$csvFile = &#039;uci.csv&#039;; \/\/ Replace with your CSV file name\r\n$icsFile = &#039;uci.ics&#039;; \/\/ Output ICS file name\r\n\r\n$handle = fopen($csvFile, &#039;r&#039;);\r\nif ($handle !== false) {\r\n    \/\/ Open ICS file for writing\r\n    $icsHandle = fopen($icsFile, &#039;w&#039;);\r\n\r\n    \/\/ Write ICS header\r\n    fwrite($icsHandle, &quot;BEGIN:VCALENDAR\\r\\n&quot;);\r\n    fwrite($icsHandle, &quot;VERSION:2.0\\r\\n&quot;);\r\n    fwrite($icsHandle, &quot;PRODID:-\/\/Your Company\/\/NONSGML Event Calendar\/\/EN\\r\\n&quot;);\r\n\r\n    \/\/ Read CSV line by line\r\n    while (($data = fgetcsv($handle, 1000, &#039;,&#039;)) !== false) {\r\n        $startDate = convertDate($data&#x5B;0]);\r\n        $endDate = convertDate($data&#x5B;1]);\r\n        print_r($data) . PHP_EOL;\r\n        echo $startDate;\r\n        \r\n        if ($startDate === false || $endDate === false) {\r\n            continue;\r\n        }\r\n        $event = escapeText($data&#x5B;2]);\r\n\r\n        \/\/ Write event to ICS file\r\n        fwrite($icsHandle, &quot;BEGIN:VEVENT\\r\\n&quot;);\r\n        fwrite($icsHandle, &quot;UID:&quot; . uniqid() . &quot;\\r\\n&quot;); \/\/ Unique identifier\r\n        fwrite($icsHandle, &quot;DTSTART;VALUE=DATE:&quot; . $startDate . &quot;\\r\\n&quot;);\r\n        fwrite($icsHandle, &quot;DTEND;VALUE=DATE:&quot; . $endDate . &quot;\\r\\n&quot;);\r\n        fwrite($icsHandle, &quot;SUMMARY:&quot; . $event . &quot;\\r\\n&quot;);\r\n        fwrite($icsHandle, &quot;DESCRIPTION:&quot; . $event . &quot;\\r\\n&quot;);\r\n        fwrite($icsHandle, &quot;END:VEVENT\\r\\n&quot;);\r\n    }\r\n\r\n    \/\/ Write ICS footer\r\n    fwrite($icsHandle, &quot;END:VCALENDAR\\r\\n&quot;);\r\n\r\n    \/\/ Close files\r\n    fclose($icsHandle);\r\n    fclose($handle);\r\n\r\n    echo &quot;ICS file generated successfully.&quot;;\r\n} else {\r\n    echo &quot;Error: Unable to open CSV file.&quot;;\r\n}\r\n<\/pre>\n<p>Source data are  from <a href=\"https:\/\/www.uci.org\/calendar\/all\/2jnxYAuvjgttyHi6YQ94EJ?discipline=ROA\">UCI<\/a> and output is <a href=\"http:\/\/www.wjst.de\/uci.ics\">here<\/a> from where it can be added as a calendar. BTW created also my first &#8220;hello world&#8221; Swift\/iPhone app <a href=\"https:\/\/www.appcoda.com\/learnuikit\/build-your-first-app.html\">using this source\u00a0<\/a>although this took a bit more time&#8230;<\/p>\n\n<p>&nbsp;<\/p>\n<div class=\"bottom-note\">\n  <span class=\"mod1\">CC-BY-NC Science Surf , accessed 26.04.2026<\/span>\n <\/div>","protected":false},"excerpt":{"rendered":"<p>Create a PHP script that can read a CSV in the form start_date, end_date, event and output as ICS file function convertDate($date) { $dateTime = DateTime::createFromFormat(&#039;m\/d\/Y&#039;, $date); if ($dateTime === false) { return false; \/\/ Return false if date parsing fails } return $dateTime-&gt;format(&#039;Ymd&#039;); } \/\/ Function to escape special characters in text function escapeText($text) &hellip; <a href=\"https:\/\/www.wjst.de\/blog\/sciencesurf\/2024\/04\/from-start-to-finish-programming-with-chatgpt-in-60s\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">From start to finish programming with ChatGPT in 60s<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[3358,2962,4875,4874],"class_list":["post-23591","post","type-post","status-publish","format-standard","hentry","category-computer-software","tag-ai","tag-calendar","tag-ics","tag-uci"],"_links":{"self":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/23591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/comments?post=23591"}],"version-history":[{"count":4,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/23591\/revisions"}],"predecessor-version":[{"id":23595,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/23591\/revisions\/23595"}],"wp:attachment":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/media?parent=23591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/categories?post=23591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/tags?post=23591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}