<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <atom:link href="http://kitchingroup.cheme.cmu.edu/blog/feed/index.xml" rel="self" type="application/rss+xml" />
    <title>The Kitchin Research Group</title>
    <link>https://kitchingroup.cheme.cmu.edu/blog</link>
    <description>Chemical Engineering at Carnegie Mellon University</description>
    <pubDate>Sat, 01 Nov 2025 13:47:46 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    
    <item>
      <title>Posting articles to CiteULike from bibtex</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2013/10/20/Posting-articles-to-CiteULike-from-bibtex</link>
      <pubDate>Sun, 20 Oct 2013 15:33:08 EDT</pubDate>
      <category><![CDATA[emacs]]></category>
      <category><![CDATA[python]]></category>
      <category><![CDATA[citeulike]]></category>
      <guid isPermaLink="false">gLrKrcrq1hyHrAgTvXxziWfucYA=</guid>
      <description>Posting articles to CiteULike from bibtex</description>
      <content:encoded><![CDATA[


&lt;div id="table-of-contents"&gt;
&lt;h2&gt;Table of Contents&lt;/h2&gt;
&lt;div id="text-table-of-contents"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#sec-1"&gt;1. Doing this in emacs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;
I have been using &lt;a href="http://www.citeulike.org/user/jkitchin"&gt;CiteULike&lt;/a&gt; for a while now to keep a list of articles that are probably worth reading. Basically, each month I get a table of contents from many journals, and as I read through them, if an article catches my attention I add it to my CiteULike account. 
&lt;/p&gt;

&lt;p&gt;
This list is not synchronized with my bibtex database however. These serve different purposes. The CiteULike list is for articles that are probably worth reading, while the bibtex file contains articles I am probably going to cite. It should be that every article in my bibtex file is on CiteULike, but not necessarily the other way around. The problem is I do not have a way to push files from my bibtex file to CiteULike easily.
&lt;/p&gt;

&lt;p&gt;
CiteULike allows you to &lt;a href="http://www.citeulike.org/profile/jkitchin/import_go"&gt;import&lt;/a&gt; a bibtex file though. I want to explore automatically importing a bibtex file by simulating the form. We need a set of cookies to make this happen so CiteULike knows who we are. I stored my username and password in a file called citeulike.json and use them to get cookies that I save here in a pickle file. I think this cookie gives you access to your CiteULike account, so it should be kept secret.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;&lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; json, pickle, requests

&lt;span style="color: #8b0000;"&gt;with&lt;/span&gt; &lt;span style="color: #cd0000;"&gt;open&lt;/span&gt;(&lt;span style="color: #228b22;"&gt;'citeulike.json'&lt;/span&gt;) &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; f:
    &lt;span style="color: #8b008b;"&gt;d&lt;/span&gt; = json.loads(f.read())

&lt;span style="color: #8b008b;"&gt;url&lt;/span&gt; = &lt;span style="color: #228b22;"&gt;'http://www.citeulike.org/login.do'&lt;/span&gt;

&lt;span style="color: #8b008b;"&gt;data&lt;/span&gt; = &lt;span style="color: #228b22;"&gt;"username={0}&amp;amp;password={1}&amp;amp;perm=1"&lt;/span&gt;.&lt;span style="color: #cd0000;"&gt;format&lt;/span&gt;(d[&lt;span style="color: #228b22;"&gt;'username'&lt;/span&gt;], d[&lt;span style="color: #228b22;"&gt;'password'&lt;/span&gt;])

&lt;span style="color: #8b008b;"&gt;r&lt;/span&gt; = requests.post(url, data=data, allow_redirects=&lt;span style="color: #cd0000;"&gt;False&lt;/span&gt;)

&lt;span style="color: #8b0000;"&gt;with&lt;/span&gt; &lt;span style="color: #cd0000;"&gt;open&lt;/span&gt;(&lt;span style="color: #228b22;"&gt;'cookies.pckl'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'wb'&lt;/span&gt;) &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; f:
    pickle.dump(r.cookies, f)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
By inspecting the &lt;a href="http://www.citeulike.org/profile/jkitchin/import_go"&gt;import&lt;/a&gt; page with Firebug, I constructed this http request to upload a bibtex string.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;&lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; pickle, requests

&lt;span style="color: #ff0000; font-weight: bold;"&gt;# &lt;/span&gt;&lt;span style="color: #ff0000; font-weight: bold;"&gt;reload cookies&lt;/span&gt;
&lt;span style="color: #8b0000;"&gt;with&lt;/span&gt; &lt;span style="color: #cd0000;"&gt;open&lt;/span&gt;(&lt;span style="color: #228b22;"&gt;'cookies.pckl'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'rb'&lt;/span&gt;) &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; f:
    &lt;span style="color: #8b008b;"&gt;cookies&lt;/span&gt; = pickle.load(f)

&lt;span style="color: #8b008b;"&gt;url&lt;/span&gt; = &lt;span style="color: #228b22;"&gt;'http://www.citeulike.org/profile/jkitchin/import_do'&lt;/span&gt;

&lt;span style="color: #8b008b;"&gt;bibtex&lt;/span&gt; = &lt;span style="color: #228b22;"&gt;'''&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;@article{zhuo-2010-co2-induc,&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;  author =       {Zhuo, Shengchi and Huang, Yongmin and Peng, Changjun&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;                  and Liu, Honglai and Hu, Ying and Jiang, Jianwen},&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;  title =        {CO2-Induced Microstructure Transition of Surfactant&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;                  in Aqueous Solution: Insight from Molecular Dynamics&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;                  Simulation},&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;  journal =      {The Journal of Physical Chemistry B},&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;  volume =       114,&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;  number =       19,&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;  pages =        {6344-6349},&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;  year =         2010,&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;  doi =          {10.1021/jp910253b},&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;  URL =          {http://pubs.acs.org/doi/abs/10.1021/jp910253b},&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;  eprint =       {http://pubs.acs.org/doi/pdf/10.1021/jp910253b}&lt;/span&gt;
&lt;span style="color: #228b22;"&gt;}'''&lt;/span&gt;

&lt;span style="color: #8b008b;"&gt;data&lt;/span&gt; = {&lt;span style="color: #228b22;"&gt;'pasted'&lt;/span&gt;:bibtex,
        &lt;span style="color: #228b22;"&gt;'to_read'&lt;/span&gt;:2,
        &lt;span style="color: #228b22;"&gt;'tag_parsing'&lt;/span&gt;:&lt;span style="color: #228b22;"&gt;'simple'&lt;/span&gt;,
        &lt;span style="color: #228b22;"&gt;'strip_brackets'&lt;/span&gt;:&lt;span style="color: #228b22;"&gt;'no'&lt;/span&gt;,
        &lt;span style="color: #228b22;"&gt;'update_id'&lt;/span&gt;:&lt;span style="color: #228b22;"&gt;'bib-key'&lt;/span&gt;,
        &lt;span style="color: #228b22;"&gt;'btn_bibtex'&lt;/span&gt;:&lt;span style="color: #228b22;"&gt;'Import BibTeX file ...'&lt;/span&gt;}

&lt;span style="color: #8b008b;"&gt;headers&lt;/span&gt; = {&lt;span style="color: #228b22;"&gt;'content-type'&lt;/span&gt;: &lt;span style="color: #228b22;"&gt;'multipart/form-data'&lt;/span&gt;,
           &lt;span style="color: #228b22;"&gt;'User-Agent'&lt;/span&gt;:&lt;span style="color: #228b22;"&gt;'jkitchin/johnrkitchin@gmail.com bibtexupload'&lt;/span&gt;}

&lt;span style="color: #8b008b;"&gt;r&lt;/span&gt; = requests.post(url, headers=headers, data=data, cookies=cookies, files={})
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
The result is that article is now listed in my CiteULike at &lt;a href="http://www.citeulike.org/user/jkitchin/article/12728895"&gt;http://www.citeulike.org/user/jkitchin/article/12728895&lt;/a&gt; .  This opens the possibility of integrating this into my bibtex workflow. I could implement this in emacs-lisp, and have it automatically upload new entries in the bibtex file to CiteULike. 
&lt;/p&gt;

&lt;div id="outline-container-sec-1" class="outline-2"&gt;
&lt;h2 id="sec-1"&gt;&lt;span class="section-number-2"&gt;1&lt;/span&gt; Doing this in emacs&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-1"&gt;
&lt;p&gt;
I think the easiest thing to do here is to write a python script that takes the bibtex string and posts it. We will use emacs to get the bibtex string. We will use the example at  &lt;a href="http://ergoemacs.org/emacs/elisp_perl_wrapper.html"&gt;http://ergoemacs.org/emacs/elisp_perl_wrapper.html&lt;/a&gt; to put this together. This example uses an external script that takes a string on stdin, and returns a result on stdout.
&lt;/p&gt;

&lt;p&gt;
We will run the function in a bibtex buffer. We will narrow the buffer to the current entry, and use that to define the boundaries of the string. We do the command in a temp-buffer to prevent it from modifying our bibtex file. There is some way to make the command not do this with optional arguments, but I did not figure it out. It is a little ugly I had to use an absolute path below. An alternative would be to put the script into a directory on your path. Here is the function.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #8b0000;"&gt;defun&lt;/span&gt; &lt;span style="color: #8b2323;"&gt;j/upload-bibtex-entry-to-citeulike&lt;/span&gt; ()
  &lt;span style="color: #228b22;"&gt;"get bibtex string and submit to citeulike"&lt;/span&gt;
  (interactive)
  (&lt;span style="color: #8b0000;"&gt;save-restriction&lt;/span&gt;
    (bibtex-narrow-to-entry)
    (&lt;span style="color: #8b0000;"&gt;let&lt;/span&gt; ((startpos (point-min))
          (endpos (point-max))
          (bibtex-string (buffer-string))
          (script &lt;span style="color: #228b22;"&gt;"python c:/Users/jkitchin/Dropbox/blogofile-jkitchin.github.com/_blog/upload_bibtex_citeulike.py"&lt;/span&gt;))
      (&lt;span style="color: #8b0000;"&gt;with-temp-buffer&lt;/span&gt; (insert bibtex-string)
                        (shell-command-on-region (point-min) (point-max) script t nil nil t)))))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Now, let us define the python script.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;&lt;span style="color: #ff0000; font-weight: bold;"&gt;#&lt;/span&gt;&lt;span style="color: #ff0000; font-weight: bold;"&gt;!python&lt;/span&gt;
&lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; pickle, requests, sys

&lt;span style="color: #ff0000; font-weight: bold;"&gt;# &lt;/span&gt;&lt;span style="color: #ff0000; font-weight: bold;"&gt;reload cookies&lt;/span&gt;
&lt;span style="color: #8b0000;"&gt;with&lt;/span&gt; &lt;span style="color: #cd0000;"&gt;open&lt;/span&gt;(&lt;span style="color: #228b22;"&gt;'c:/Users/jkitchin/Dropbox/blogofile-jkitchin.github.com/_blog/cookies.pckl'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'rb'&lt;/span&gt;) &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; f:
    &lt;span style="color: #8b008b;"&gt;cookies&lt;/span&gt; = pickle.load(f)

&lt;span style="color: #8b008b;"&gt;url&lt;/span&gt; = &lt;span style="color: #228b22;"&gt;'http://www.citeulike.org/profile/jkitchin/import_do'&lt;/span&gt;

&lt;span style="color: #8b008b;"&gt;bibtex&lt;/span&gt; = sys.stdin.read()

&lt;span style="color: #8b008b;"&gt;data&lt;/span&gt; = {&lt;span style="color: #228b22;"&gt;'pasted'&lt;/span&gt;:bibtex,
        &lt;span style="color: #228b22;"&gt;'to_read'&lt;/span&gt;:2,
        &lt;span style="color: #228b22;"&gt;'tag_parsing'&lt;/span&gt;:&lt;span style="color: #228b22;"&gt;'simple'&lt;/span&gt;,
        &lt;span style="color: #228b22;"&gt;'strip_brackets'&lt;/span&gt;:&lt;span style="color: #228b22;"&gt;'no'&lt;/span&gt;,
        &lt;span style="color: #228b22;"&gt;'update_id'&lt;/span&gt;:&lt;span style="color: #228b22;"&gt;'bib-key'&lt;/span&gt;,
        &lt;span style="color: #228b22;"&gt;'btn_bibtex'&lt;/span&gt;:&lt;span style="color: #228b22;"&gt;'Import BibTeX file ...'&lt;/span&gt;}

&lt;span style="color: #8b008b;"&gt;headers&lt;/span&gt; = {&lt;span style="color: #228b22;"&gt;'content-type'&lt;/span&gt;: &lt;span style="color: #228b22;"&gt;'multipart/form-data'&lt;/span&gt;,
           &lt;span style="color: #228b22;"&gt;'User-Agent'&lt;/span&gt;:&lt;span style="color: #228b22;"&gt;'jkitchin/johnrkitchin@gmail.com bibtexupload'&lt;/span&gt;}

&lt;span style="color: #8b008b;"&gt;r&lt;/span&gt; = requests.post(url, headers=headers, data=data, cookies=cookies, files={})
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
That is it. Now, in my bibtex file with the cursor in an entry, I type M-x j/upload-bibtex-entry-to-citeulike, and a few seconds later the entry has been uploaded! 
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2013 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2013/10/20/Posting-articles-to-CiteULike-from-bibtex.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;]]></content:encoded>
    </item>
  </channel>
</rss>
