practicalli / practicalli/clojure
Emailing from Clojure - using SendGrid API
Nobody has claimed this yet.
- Dominant language
- Makefile
- Stars
- 117
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
Description
https://andersmurphy.com/2019/01/06/clojure-sending-emails-with-sendgrid.html
Related:
https://stackoverflow.com/a/16217166/1762872
you shouldn't escape commas - you should quote the entry. the higher-voted answer there has a link to the "spec" (as much as it is), which is what the org.clojure/data.csv library follows (the only Clojure csv parser I use regularly)
18:29
$ clj -Sdeps '{:deps {org.clojure/data.csv {:mvn/version "1.0.0"}}}'
Clojure 1.10.1
user=> (require '[clojure.data.csv :as csv])
nil
user=> (csv/read-csv ""a,b",c")
(["a,b" "c"])
ach clj 18:38
Got it. Will try that. I'm trying to follow the guide at https://andersmurphy.com/2019/01/06/clojure-sending-emails-with-sendgrid.html
However, if the data is like:
[{:id 1, :t_id "1311350232249065472", :text "6b/ Substack: "We've just been growing fairly consistently, and gradually the how-do-we-keep-up anxiety got bigger and bigger until there wasn't time left in the day to worry about whether we had product-market fit." – @cjgbest", :created_at "2020-10-01T12:17:34.611062000-00:00"}]
The resultant csv creates new column for every comma word between the commas (2nd row)
(csv/read-csv ""id","t_id","text","created_at"\n"1","1311350232249065472","6b/ Substack: "We've just been growing fairly consistently, and gradually the how-do-we-keep-up anxiety got bigger and bigger until there wasn't time left in the day to worry about whether we had product-market fit." – @cjgbest","2020-10-01T12:17:34.611062000-00:00"")
; Error printing return value at clojure.data.csv/read-quoted-cell (csv.clj:37).
; CSV error (unexpected character: W)
Re the " before We've - I would usually expect that to be escaped with a double quote instead ""We've
19:54
and from a glance at the data.csv code that's what it's expecting too
19:56
but csv is notoriously non-standardized
ach clj 19:58
Hmm, the data from the db itself has "
[{:id 1, :t_id "1311350232249065472", :text "6b/ Substack: "We've just been growing fairly consistently, and gradually the how-do-we-keep-up anxiety got bigger and bigger until there wasn't time left in the day to worry about whether we had product-market fit." – @cjgbest", :created_at "2020-10-01T12:17:34.611062000-00:00"}]
How should I go about turning this into a valid csv structure/string?
yeah, you have to deal with the data you have
if I had to go out on a limb, I suspect you're not going to see that " other than this case, so you could str/replace that with "", have no idea how often that would go wrong but might be a useful hack
I'll try that.
How did you write that csv?
I would say the code generating that csv is not correctly escaping quotes, so if you are generating the csv you should fix that code
it sounds like that's data from someone else
hell is other people's data right?
The linked to blog post includes code for naively creating csvs without any escaping
Which is why I suggested data.csv
But you will need to generate the csv using data.csv, not the obviously incorrect code in that blog post
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the linked SendGrid/CSV guide and org.clojure/data.csv, especially clojure.data.csv/read-quoted-cell at csv.clj:37. Determine whether the problem is in the guide's CSV generation or in data.csv, then document a reproducible scope and a clear expected result before changing anything.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100