jarun / ddgr

:duck: DuckDuckGo from the terminal
GNU General Public License v3.0
2.94k stars 139 forks source link

Error writing to JSON files #91

Closed l-jdavies closed 5 years ago

l-jdavies commented 5 years ago

Hi,

I have a bash shell script to loop through a list of terms, perform ddgr and write the output to a json file. For every second term I'm receiving the error: invalid width -5 (must be > 0)

image

Any advice would be appreciated! Cheers

jarun commented 5 years ago

Please debug yourself and raise a patch. I don't have bandwidth.

l-jdavies commented 5 years ago

I don't know how to do that. Sorry.

jarun commented 5 years ago

ddgr already supports json output. You can use that.

l-jdavies commented 5 years ago

I am using it. I'm running ddgr --json "$line" </dev/null >> /home/DAVIEL20/Data/FungiSeq/Run_6.2-ITS1Oo-ITS7ae/Analysis/ITS1Oo-unknowns-to-google-results-txt.json in a bash shell script to loop through a list of search terms. I get the error every other search term.

jarun commented 5 years ago

Try without -d. And do you see any issue if you just run ddgr with -j without your script?

l-jdavies commented 5 years ago

I don't get the error if I only run ddgr -j keyword once but I get the error if I run that same command multiple times. The html file saved to the tmp folder is fine, the problem is with parsing to json.

jarun commented 5 years ago

if I run that same command multiple times

through the script? In that case it looks like your script may not be handling characters correctly. Also check if the json output from ddgr is malformed.

l-jdavies commented 5 years ago

Even if I manually enter the command several times in the terminal I get the error every second time the command is entered. When I get the error the json file is empty.

l-jdavies commented 5 years ago

It's strange but I appear to get the error when the search term is a scientific term. When I enter ddgr --json absidia > absidia.json in the terminal I receive the error message. I've tried running the same script but using a list of random words as the input file and that worked just fine.

jarun commented 5 years ago

OK. I see the error now:

$ ddgr --json absidia

     Absidia is a genus of fungi in the family Cunninghamellaceae. The best-known species is the
     pathogenic Absidia corymbifera, which causes zygomycosis, especially in the form of mycotic
     spontaneous abortion in cows. It can also cause mucormycosis in humans. It is an allergenic that
     could cause mucorosis in individuals with low immunity. It usually infects the lungs, nose, brain,
     eyesight and skin. Absidia spp. are ubiquitous in most environments.                          More at
     Wikipedia
[ERROR] Object of type 'generator' is not JSON serializable
jarun commented 5 years ago

I think there's a regression in mater. v1.6 does not have this issue.

jarun commented 5 years ago

@Arian-D commit 8ce935db6406a0fb6c92dd0fe408bd74f7f013bb breaks this. Please look into it.

jarun commented 5 years ago

For the time being I have reverted both the changes.

@drljdavies can you please check if master works for you?

Arian-D commented 5 years ago

If i'm not mistaken, it was this line that caused this issue. Master seems to be working after reverting the changes.

l-jdavies commented 5 years ago

It's working now. Thanks for your help.