-
Notifications
You must be signed in to change notification settings - Fork 6
/
mend-to-bibtex.R
88 lines (50 loc) · 2.43 KB
/
mend-to-bibtex.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
######################################################################
######################################################################
#### ####
#### How this thing works ####
#### ####
######################################################################
######################################################################
## Input:
## - MendeleySQL: the mendeley sqlite db (make a copy just in case)
## - BibTexFile: the bibtex file that Mendeley produces.
## Before starting, remember to clean the trash of mendeley and then copy
## or link the sqlite file.
## Output
## - out: a bibtex file that you can then import into Zotero
## Other things you need to specify and we assume:
## - tmpFilePaths: a temporary holder for files. We rename many
## files. This directory needs to exist. Files will be placed in there,
## and Zotero will take files from there. After all is done, you can
## remove it.
## Remember to empty the trash of mendeley
MendeleySQL <- "mend.sqlite"
BibTeXFile <- "library-fixed.bib"
out <- "new-library.bib" ## the new bibtex file that will be created
tmpFilePaths <- "/home/ramon/tmp/mend" ## A temporary directory for
## placing renamed files.
source("sqlite-bibtex-functions.R")
con <- dbConnect(SQLite(), MendeleySQL)
minimalDBchecks(con)
## Continue if things are ok
res <- dbGetQuery(con, sqliteQuery1)
res$timestamp <- getTimestamp(res)
minimalDBDFchecks(res)
bibfile <- myBibtexReaderandCheck(BibTeXFile)
bibtexDBConsistencyCheck(res, bibfile)
## Continue if things are ok
## Add the extra information not exported by default by Mendeley
bibfile2 <- addInfoToBibTex(bibfile, res)
## Fix file names: nothing longer than maxlength and no spaces or special
## chars in in file names.
bibfileFileFixed <- fixFileNames(bibfile2, tmpFilePaths)
jabrefGr <- jabrefGroups(con, res)
## If you want to see what it looks like
## write(file = "jabref-groups.txt",
## jabrefGr)
outFullBibTex(bibfileFileFixed, jabrefGr, out)
## You should have the bibtex file in the one you called out. Go import
## that into Zotero. You might want to first import into JabRef and see
## what happens.
## After imported OK into Zotero, you might want to fix the dates. See
## general instructions in README.md.