Posts database functions.
Constantes
Text PdbSepFunciones
Set PdbRead(Text inpDir)Set PdbFirstN(Set inpSet, Real maxNum, Code funSel)Set PdbYearSet(Text inpDir)//////////////////////////////////////////////////////////////////////////////
Text PdbSep = Repeat("_",78);
//////////////////////////////////////////////////////////////////////////////
PutDescription("Post separator inside the agendas.", PdbSep);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set PdbRead(Text inpDir)
//////////////////////////////////////////////////////////////////////////////
{
Real err(Text msg) { Text WriteLn("\nERROR: "+msg+"\n"); FALSE }; // Function
Text filSep = Char(7);
Text WriteLn("Reading "+inpDir+"...");
Text inpAll = DirReadFiles(inpDir, "age", filSep);
Text inpTxt = Replace(inpAll, PdbSep+"\n",filSep);
Set inpSet = Tokenizer(inpTxt,filSep);
Set inpTab = EvalSet(inpSet, Set(Text inf)
{
// Read
Text pstSta = Sub(TxtBetween2Tag(inf, "<Pst.Sta>", "\n<Pst.", TRUE) +
"C",1,1); // C por defecto
Text pstFil = TxtBetween2Tag(inf, "<Pst.Fil>", "\n<Pst.", TRUE);
Text pstTit = TxtBetween2Tag(inf, "<Pst.Tit>", "\n<Pst.", TRUE);
Text pstHtm = TxtBetween2Tag(inf, "<Pst.Txt>", "\n<Pst.", FALSE);
Text pstRes = TxtOutside2Tag(pstHtm,"<!--INI-->","<!--END-->"); // Resumen
Set pstCla =
Txt2Set(TxtBetween2Tag(inf, "<Pst.Cla>", "\n<Pst.", TRUE), ";") <<
SetOfText("Post", Sub(pstFil, 1, 4)); // All are post + publication year
Text pstTxt = TxtOutHtmScr(pstHtm);
// Camino completo y limpio
Text pstPth = PhtCleanFilePath("noticia", pstFil, "html");
// Check
Set chkCla = EvalSet(pstCla, Real(Text claNam) // Category class
{ If(claNam <: CatAll, TRUE, err("Class: "+claNam+" file: "+pstFil)) });
// Store
Set pstObj = PdbSt(pstCla,
pstSta,
pstPth,
pstTit,
pstHtm,
pstRes,
pstTxt);
pstObj
});
Set inpSel = Select(inpTab, Real(Set a) { a->pstSta!="A" }); // Not deleted
// Check
Real chkDup =
{
Set codCla = Classify(inpTab, Real(Set a, Set b)
{ Compare(a->pstFil, b->pstFil) });
Set filDup = EvalSet(codCla, Real(Set cla)
{
Real crd = Card(cla);
Text nam = cla[1]->pstFil;
If(EQ(crd,1), TRUE, err("Name: "+nam+" "+F(crd)+" times"))
});
Card(filDup)
};
Text WriteLn("Status ABCD "+F(Card(inpTab))+" registers");
Text WriteLn("Status _BCD "+F(Card(inpSel))+" registers");
Set inpSor = Sort(inpSel, Real(Set a, Set b) // Reverse file order
{ Compare(b->pstFil, a->pstFil) });
inpSor // Los ficheros van con fecha, los mas modernos primero
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Reads and returns a post database as a set of structures.",
PdbRead);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set PdbFirstN(Set inpSet, // Post database
Real maxNum, // Maximum numbers of posts to return
Code funSel) // Post selection conditions
//////////////////////////////////////////////////////////////////////////////
{
Set selFst = Select(inpSet, funSel); // Select all that funSel()
SetFirstN(selFst, maxNum) // Fst maxNum or all if there are few
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns the maxNum recents posts selected using the function funSel.",
PdbFirstN);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set PdbYearSet(Text inpDir)
//////////////////////////////////////////////////////////////////////////////
{
Text WriteLn("Reading "+inpDir+" years...");
Set pthSet = DirExtAll(inpDir, "age", FALSE, TRUE);
Set yeaSet = EvalSet(pthSet, Text(Text pthFil)
{ TxtBetween2Tag(pthFil, inpDir+"/", ".", TRUE) }); // agenda/2013.encue...
// Agrupa años iguales y ordena de más reciente a más antiguo
Set yeaCla = Classify(yeaSet, Real(Text a, Text b) { Compare(b,a) });
EvalSet(yeaCla, Text(Set claSet) { claSet[1] }) // Uno por clase
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a set with all the years numbers, as texts, that have published
posts in the agenda directory inpDir.",
PdbYearSet);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// FILE : pdb.tol
// AUTHOR : http://www.asolver.com
// PURPOSE : Posts database functions.
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// CONSTANTS
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text PdbSep = Repeat("_",78);
//////////////////////////////////////////////////////////////////////////////
PutDescription("Post separator inside the agendas.", PdbSep);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set PdbRead(Text inpDir)
//////////////////////////////////////////////////////////////////////////////
{
Real err(Text msg) { Text WriteLn("\nERROR: "+msg+"\n"); FALSE }; // Function
Text filSep = Char(7);
Text WriteLn("Reading "+inpDir+"...");
Text inpAll = DirReadFiles(inpDir, "age", filSep);
Text inpTxt = Replace(inpAll, PdbSep+"\n",filSep);
Set inpSet = Tokenizer(inpTxt,filSep);
Set inpTab = EvalSet(inpSet, Set(Text inf)
{
// Read
Text pstSta = Sub(TxtBetween2Tag(inf, "<Pst.Sta>", "\n<Pst.", TRUE) +
"C",1,1); // C por defecto
Text pstFil = TxtBetween2Tag(inf, "<Pst.Fil>", "\n<Pst.", TRUE);
Text pstTit = TxtBetween2Tag(inf, "<Pst.Tit>", "\n<Pst.", TRUE);
Text pstHtm = TxtBetween2Tag(inf, "<Pst.Txt>", "\n<Pst.", FALSE);
Text pstRes = TxtOutside2Tag(pstHtm,"<!--INI-->","<!--END-->"); // Resumen
Set pstCla =
Txt2Set(TxtBetween2Tag(inf, "<Pst.Cla>", "\n<Pst.", TRUE), ";") <<
SetOfText("Post", Sub(pstFil, 1, 4)); // All are post + publication year
Text pstTxt = TxtOutHtmScr(pstHtm);
// Camino completo y limpio
Text pstPth = PhtCleanFilePath("noticia", pstFil, "html");
// Check
Set chkCla = EvalSet(pstCla, Real(Text claNam) // Category class
{ If(claNam <: CatAll, TRUE, err("Class: "+claNam+" file: "+pstFil)) });
// Store
Set pstObj = PdbSt(pstCla,
pstSta,
pstPth,
pstTit,
pstHtm,
pstRes,
pstTxt);
pstObj
});
Set inpSel = Select(inpTab, Real(Set a) { a->pstSta!="A" }); // Not deleted
// Check
Real chkDup =
{
Set codCla = Classify(inpTab, Real(Set a, Set b)
{ Compare(a->pstFil, b->pstFil) });
Set filDup = EvalSet(codCla, Real(Set cla)
{
Real crd = Card(cla);
Text nam = cla[1]->pstFil;
If(EQ(crd,1), TRUE, err("Name: "+nam+" "+F(crd)+" times"))
});
Card(filDup)
};
Text WriteLn("Status ABCD "+F(Card(inpTab))+" registers");
Text WriteLn("Status _BCD "+F(Card(inpSel))+" registers");
Set inpSor = Sort(inpSel, Real(Set a, Set b) // Reverse file order
{ Compare(b->pstFil, a->pstFil) });
inpSor // Los ficheros van con fecha, los mas modernos primero
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Reads and returns a post database as a set of structures.",
PdbRead);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set PdbFirstN(Set inpSet, // Post database
Real maxNum, // Maximum numbers of posts to return
Code funSel) // Post selection conditions
//////////////////////////////////////////////////////////////////////////////
{
Set selFst = Select(inpSet, funSel); // Select all that funSel()
SetFirstN(selFst, maxNum) // Fst maxNum or all if there are few
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns the maxNum recents posts selected using the function funSel.",
PdbFirstN);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set PdbYearSet(Text inpDir)
//////////////////////////////////////////////////////////////////////////////
{
Text WriteLn("Reading "+inpDir+" years...");
Set pthSet = DirExtAll(inpDir, "age", FALSE, TRUE);
Set yeaSet = EvalSet(pthSet, Text(Text pthFil)
{ TxtBetween2Tag(pthFil, inpDir+"/", ".", TRUE) }); // agenda/2013.encue...
// Agrupa años iguales y ordena de más reciente a más antiguo
Set yeaCla = Classify(yeaSet, Real(Text a, Text b) { Compare(b,a) });
EvalSet(yeaCla, Text(Set claSet) { claSet[1] }) // Uno por clase
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a set with all the years numbers, as texts, that have published
posts in the agenda directory inpDir.",
PdbYearSet);
//////////////////////////////////////////////////////////////////////////////
con-Q.tv construye las páginas del sitio y newsletter Con-Q.tv
2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio