Created
April 23, 2024 20:34
-
-
Save doccaico/c13b9f876bbbe77538ff471158828c81 to your computer and use it in GitHub Desktop.
convert tweets.js to markdown in V
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import x.json2 | |
import os | |
struct Tweets { | |
tweet struct { | |
created_at string | |
full_text string | |
} | |
} | |
fn write_text(s string, key string) ! { | |
year := key[..4] | |
month := key[5..] | |
mut text := '### ${key}\n' | |
text += s | |
os.write_file('contents/${year}${month}.md', text)! | |
// println('${year} ${month}') | |
} | |
fn main() { | |
// js_path := 'test.js' | |
js_path := 'tweets.js' | |
js_content := os.read_file(js_path)! | |
tweets := json2.decode_array[Tweets](js_content)! | |
// mut result := map[string]string{} | |
mut result := map[string][]string{} | |
for t in tweets { | |
created_at := t.tweet.created_at | |
full_text := t.tweet.full_text | |
year := created_at#[-4..] | |
month := match created_at[4..7] { | |
'Jan' { '01' } | |
'Feb' { '02' } | |
'Mar' { '03' } | |
'Apr' { '04' } | |
'May' { '05' } | |
'Jun' { '06' } | |
'Jul' { '07' } | |
'Aug' { '08' } | |
'Sep' { '09' } | |
'Oct' { '10' } | |
'Nov' { '11' } | |
'Dec' { '12' } | |
else { '' } | |
} | |
day := created_at[8..10] | |
time_ := created_at[11..16] | |
mut md := '' | |
md += '#### ${day} ${time_}\n' | |
md += '${full_text}\n' | |
result['${year}/${month}'] << [md] | |
} | |
for k, _ in result { | |
result[k].sort(a > b) | |
write_text(result[k].join(''), k)! | |
} | |
// print(result['2022/05']) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment