\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{from} \PYG{n+nn}{Bio} \PYG{k+kn}{import} \PYG{n}{Entrez}

\PYG{n}{Entrez}\PYG{o}{.}\PYG{n}{email} \PYG{o}{=} \PYG{l+s+s2}{\PYGZdq{}history.user@example.com\PYGZdq{}}
\PYG{n}{search\PYGZus{}results} \PYG{o}{=} \PYG{n}{Entrez}\PYG{o}{.}\PYG{n}{read}\PYG{p}{(}
    \PYG{n}{Entrez}\PYG{o}{.}\PYG{n}{esearch}\PYG{p}{(}
        \PYG{n}{db}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}pubmed\PYGZdq{}}\PYG{p}{,} \PYG{n}{term}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}Opuntia[ORGN]\PYGZdq{}}\PYG{p}{,} \PYG{n}{reldate}\PYG{o}{=}\PYG{l+m+mi}{365}\PYG{p}{,} \PYG{n}{datetype}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}pdat\PYGZdq{}}\PYG{p}{,} \PYG{n}{usehistory}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}y\PYGZdq{}}
    \PYG{p}{)}
\PYG{p}{)}
\PYG{n}{count} \PYG{o}{=} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{search\PYGZus{}results}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}Count\PYGZdq{}}\PYG{p}{])}
\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}Found }\PYG{l+s+si}{\PYGZpc{}i}\PYG{l+s+s2}{ results\PYGZdq{}} \PYG{o}{\PYGZpc{}} \PYG{n}{count}\PYG{p}{)}

\PYG{n}{batch\PYGZus{}size} \PYG{o}{=} \PYG{l+m+mi}{10}
\PYG{n}{out\PYGZus{}handle} \PYG{o}{=} \PYG{n+nb}{open}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}recent\PYGZus{}orchid\PYGZus{}papers.txt\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}w\PYGZdq{}}\PYG{p}{)}
\PYG{k}{for} \PYG{n}{start} \PYG{o+ow}{in} \PYG{n+nb}{range}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{,} \PYG{n}{count}\PYG{p}{,} \PYG{n}{batch\PYGZus{}size}\PYG{p}{):}
    \PYG{n}{end} \PYG{o}{=} \PYG{n+nb}{min}\PYG{p}{(}\PYG{n}{count}\PYG{p}{,} \PYG{n}{start} \PYG{o}{+} \PYG{n}{batch\PYGZus{}size}\PYG{p}{)}
    \PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}Going to download record }\PYG{l+s+si}{\PYGZpc{}i}\PYG{l+s+s2}{ to }\PYG{l+s+si}{\PYGZpc{}i}\PYG{l+s+s2}{\PYGZdq{}} \PYG{o}{\PYGZpc{}} \PYG{p}{(}\PYG{n}{start} \PYG{o}{+} \PYG{l+m+mi}{1}\PYG{p}{,} \PYG{n}{end}\PYG{p}{))}
    \PYG{n}{fetch\PYGZus{}handle} \PYG{o}{=} \PYG{n}{Entrez}\PYG{o}{.}\PYG{n}{efetch}\PYG{p}{(}
        \PYG{n}{db}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}pubmed\PYGZdq{}}\PYG{p}{,}
        \PYG{n}{rettype}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}medline\PYGZdq{}}\PYG{p}{,}
        \PYG{n}{retmode}\PYG{o}{=}\PYG{l+s+s2}{\PYGZdq{}text\PYGZdq{}}\PYG{p}{,}
        \PYG{n}{retstart}\PYG{o}{=}\PYG{n}{start}\PYG{p}{,}
        \PYG{n}{retmax}\PYG{o}{=}\PYG{n}{batch\PYGZus{}size}\PYG{p}{,}
        \PYG{n}{webenv}\PYG{o}{=}\PYG{n}{search\PYGZus{}results}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}WebEnv\PYGZdq{}}\PYG{p}{],}
        \PYG{n}{query\PYGZus{}key}\PYG{o}{=}\PYG{n}{search\PYGZus{}results}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}QueryKey\PYGZdq{}}\PYG{p}{],}
    \PYG{p}{)}
    \PYG{n}{data} \PYG{o}{=} \PYG{n}{fetch\PYGZus{}handle}\PYG{o}{.}\PYG{n}{read}\PYG{p}{()}
    \PYG{n}{fetch\PYGZus{}handle}\PYG{o}{.}\PYG{n}{close}\PYG{p}{()}
    \PYG{n}{out\PYGZus{}handle}\PYG{o}{.}\PYG{n}{write}\PYG{p}{(}\PYG{n}{data}\PYG{p}{)}
\PYG{n}{out\PYGZus{}handle}\PYG{o}{.}\PYG{n}{close}\PYG{p}{()}
\end{Verbatim}
