Skip to content

Instantly share code, notes, and snippets.

@anant347
Last active March 22, 2021 06:18
Show Gist options
  • Save anant347/21ab974526f70328f4773b8f3e7cbbdc to your computer and use it in GitHub Desktop.
Save anant347/21ab974526f70328f4773b8f3e7cbbdc to your computer and use it in GitHub Desktop.
Mendeley and Latex (making the file look better and replacing 'url' and 'urldate' with 'howpublished' and 'note')
#Making latex and mendeley work together
with open('references.txt','r') as file: #EDIT FILENAME IF NEEDED. PUT IN SAME FOLDER
D=file.readlines()
change_url=False
for i in range(len(D)):
a=D[i]
if a[0:5]=='@misc':
change_url=True
if a[0]=='@' or a[0]=='\n' or a[0]=='}\n' or a[0]=='{\n' or a[0]=='}' or a[0]=='{':
if a=='}\n':
change_url='False'
continue
a=a.split('=')
a1=a[0].strip()
a2=''
for j in a[1:]:
a2+=j
a2=a2.strip()
if change_url==True:
if a1=='url':
a1='howpublished'
a2='{\\url'+a2[:-1]+'},'
if a1=='urldate':
a1='note'
a2='{Accessed: '+a2[1:]
a1=a1+' '*(14-len(a1))+'= '
a=a1+a2+'\n'
D[i]=a
i=0
while i<len(D):
a=D[i]
if a[0:15]=='mendeley-groups':
del(D[i])
continue
if a[0:4]=='file':
del(D[i])
continue
if a[0:8]=='abstract':
del(D[i])
continue
i+=1
with open('references.txt','w') as file:
file.writelines(D)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment