Oxford University Press Very Short Introductions book series

Managing electronic book  files

Numbering

$dir="/Volumes/LIBRARY3/DataSpace-Library-Library3-main/book_set/Very_Short_Introductions/Very Short Introductions__Oxford_University_Press/";
$dir="/Volumes/LIBRARY3/DataSpace-Library-Library3-main/book_set/Very_Short_Introductions/inbox/";

$files=FileNames["*.*",{$dir}]

RightComposition[
With[
{
n=#,
nn=FileNameJoin[{$dir,StringReplace[FileNameTake[#,-1],RegularExpression["^(\\d{2})__(.*)$"]-> "0$1__$2"]}]
},
If[n=!=nn,RenameFile[n,nn]]
]&/@#&
][$files]

New electronic book files

Removing already existing files

$curatedBookDir="/Volumes/LIBRARY3/DataSpace-Library-Library3-main/book_set/Very_Short_Introductions/Very_Short_Introductions__Oxford_University_Press";

$curatedBooks=FileNames["*.*",{$curatedBookDir}]

$curatedBooksData=RightComposition[
{#,RandomSample[#,5]}[[1]]&,
(#-> {
"FileHash"-> FileHash[#,"MD5","HexString"]
})&/@#&
][$curatedBooks]

RightComposition[
(#[[1]]-> #[[2,1,2]])&/@#&,
GatherBy[#,#[[2]]&]&,
Cases[#,{_,__}]&
][$curatedBooksData]

$bookInboxDir="/Volumes/LIBRARY3/DataSpace-Library-Library3-main/book_set/Very_Short_Introductions/inbox";

$inboxBooks=FileNames["*.*",{$bookInboxDir}];

With[
{h=("FileHash"/.#)&/@$curatedBooksData[[All,2]]},
RightComposition[
(*RandomSample[#,5]&,*)
With[
{hh=FileHash[#,"MD5","HexString"]},
If[
MatchQ[Select[h,hh===#&],{__}],
(*DeleteFile[#]*)
Print[Style[FileNameTake[#,-1],Darker[Green]]],
Print[Style[FileNameTake[#,-1],Red]]
]
]&/@#&
][$inboxBooks]
]

$curatedBooksData[[All,2]]//Length

$curatedBooksData[[All,2]]//DeleteDuplicates//Length

With[
{h=("FileHash"/.#)&/@$curatedBooksData[[All,2]]},
RightComposition[
(*RandomSample[#,5]&,*)
With[
{hh=FileHash[#,"MD5","HexString"]},
If[
MatchQ[Select[h,hh===#&],{__}],
(*DeleteFile[#]*)
Print[Style[FileNameTake[#,-1],Darker[Green]]],
Print[Style[FileNameTake[#,-1],Red]]
]
]&/@#&
][$inboxBooks]
]

Normalizing file names

$bookInboxDir="/Volumes/LIBRARY3/DataSpace-Library-Library3-main/book_set/Very_Short_Introductions/Very_Short_Introductions__Oxford_University_Press_(epub)";$bookInboxDir="/Volumes/LIBRARY3/DataSpace-Library-Library3-main/book_set/Very_Short_Introductions/inbox";

$inboxBooks=FileNames["*.*",{$bookInboxDir}];

RightComposition[
Sort,
#[[;;]]&,
With[
{bn=StringReplace[StringReplace[StringTrim[FileBaseName[#]]," "-> "_"],RegularExpression["(.*)：_A_Very_Short_Introduction.*$"]-> "$1"]},
Print[bn];
With[
{nn=Select[$vsiBookData,bn===StringReplace[#[[2]]," "-> "_"]||"The_"<>bn===StringReplace[#[[2]]," "-> "_"]&]},
If[
MatchQ[nn,{__}],
RenameFile[#,FileNameJoin[{$bookInboxDir,nn[[1,1]]<>"__"<>StringReplace[nn[[1,2]]," "-> "_"]<>".pdf"}]],
RenameFile[#,FileNameJoin[{$bookInboxDir,bn<>".pdf"}]]
]
]
]&/@#&
][$inboxBooks]

Scraping data

RightComposition[
StringSplit
][$rawDataString]

Raw data string

$vsiBookData=RightComposition[
First,
Rest,
#[[All,{1,2}]]&,
(*RandomSample[#,5]&,*)
{StringTrim[#[[1]]],#[[2]]}&/@#&,
Cases[#,{_?(StringQ[#]&&StringMatchQ[#,RegularExpression["^\\d+$"]]&),_}]&,
(#[[1]]-> #[[2]])&/@#&
][$rawData]

Importing

$rawData=Import["~/Temp/VSI.xlsx"]