Skip to content

Commit

Permalink
xml export now works.
Browse files Browse the repository at this point in the history
  • Loading branch information
lavedon committed May 4, 2021
1 parent 2563291 commit 09bf80c
Show file tree
Hide file tree
Showing 78 changed files with 1,720 additions and 83 deletions.
9 changes: 7 additions & 2 deletions API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,14 @@ public static void APICalls(CurrentQuery query)
// @TODO add all quotes whether you have seen them or not?
query.Quotes.Add(currentQuote);
Console.WriteLine();
Console.WriteLine("----Enter for more - X to exit----");
Console.WriteLine("---- S to Save - X to exit - Enter for more----");
string input = Console.ReadLine().Trim().ToLower();
if (input == "x")
if (input == "s")
{
Console.WriteLine("Quote saved.");
SavedQueries.AddQuote(currentQuote);
}
else if (input == "x")
break;
}
catch (Exception ex) {
Expand Down
9 changes: 9 additions & 0 deletions ConsoleUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ static void MainMenu(CurrentQuery query)
API.APICalls(query);
break;

case ("e" or "export" or "export results"):
Trace.WriteLine("Export quotations.");
if (SavedQueries.Quotes.Count != 0)
SavedQueries.RenderXML();
else {
Console.WriteLine("You have not yet saved anything for export.");
}
break;

case ("x" or "exit"):
Trace.WriteLine("Exit selected.");
running = false;
Expand Down
49 changes: 49 additions & 0 deletions OED-export.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<SuperMemoCollection>
<Count>5</Count>
<SuperMemoElement>
<ID>1</ID>
<Title>W. Turner - 1548</Title>
<Type>Topic</Type>
<Content>
<Question>Carettes growe in al countreis in plentie. --W. Turner, 1548</Question>
<SuperMemoReference>&amp;lt;H5 dir=ltr align=left&amp;gt;&amp;lt;Font size=&amp;quot;1&amp;quot; style=&amp;quot;color: transparent&amp;quot;&amp;gt; SuperMemo Reference:&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;FONT class=reference&amp;gt;Title:&amp;quot;My Test Quote&amp;quot; &amp;lt;br&amp;gt;Source: Oxford English Dictionary</SuperMemoReference>
</Content>
</SuperMemoElement>
<SuperMemoElement>
<ID>2</ID>
<Title>T. Cooper - 1565</Title>
<Type>Topic</Type>
<Content>
<Question>Carota..the wilde caret. --T. Cooper, 1565</Question>
<SuperMemoReference>&amp;lt;H5 dir=ltr align=left&amp;gt;&amp;lt;Font size=&amp;quot;1&amp;quot; style=&amp;quot;color: transparent&amp;quot;&amp;gt; SuperMemo Reference:&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;FONT class=reference&amp;gt;Title:&amp;quot;My Test Quote&amp;quot; &amp;lt;br&amp;gt;Source: Oxford English Dictionary</SuperMemoReference>
</Content>
</SuperMemoElement>
<SuperMemoElement>
<ID>3</ID>
<Title> - 1634</Title>
<Type>Topic</Type>
<Content>
<Question>Parsenipps and carrootes. --, 1634</Question>
<SuperMemoReference>&amp;lt;H5 dir=ltr align=left&amp;gt;&amp;lt;Font size=&amp;quot;1&amp;quot; style=&amp;quot;color: transparent&amp;quot;&amp;gt; SuperMemo Reference:&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;FONT class=reference&amp;gt;Title:&amp;quot;My Test Quote&amp;quot; &amp;lt;br&amp;gt;Source: Oxford English Dictionary</SuperMemoReference>
</Content>
</SuperMemoElement>
<SuperMemoElement>
<ID>4</ID>
<Title>R. Cotgrave - 1611</Title>
<Type>Topic</Type>
<Content>
<Question>Calculateur, a reckoner, calculator. --R. Cotgrave, 1611</Question>
<SuperMemoReference>&amp;lt;H5 dir=ltr align=left&amp;gt;&amp;lt;Font size=&amp;quot;1&amp;quot; style=&amp;quot;color: transparent&amp;quot;&amp;gt; SuperMemo Reference:&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;FONT class=reference&amp;gt;Title:&amp;quot;My Test Quote&amp;quot; &amp;lt;br&amp;gt;Source: Oxford English Dictionary</SuperMemoReference>
</Content>
</SuperMemoElement>
<SuperMemoElement>
<ID>5</ID>
<Title>D. Defoe - 1722</Title>
<Type>Topic</Type>
<Content>
<Question>Calculators of Nativities. --D. Defoe, 1722</Question>
<SuperMemoReference>&amp;lt;H5 dir=ltr align=left&amp;gt;&amp;lt;Font size=&amp;quot;1&amp;quot; style=&amp;quot;color: transparent&amp;quot;&amp;gt; SuperMemo Reference:&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;FONT class=reference&amp;gt;Title:&amp;quot;My Test Quote&amp;quot; &amp;lt;br&amp;gt;Source: Oxford English Dictionary</SuperMemoReference>
</Content>
</SuperMemoElement>
</SuperMemoCollection>
26 changes: 19 additions & 7 deletions OptionsMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public static void ShowOptionsMenu(CurrentQuery query)
Console.WriteLine("-------------------------");
Console.WriteLine("Options Menu:");
Console.WriteLine("-------------------------");
if (SavedQueries.DeleteOnExport)
{
yesNo = "Yes";
}
else {
yesNo = "No";
}
Console.WriteLine($"Delete old XML file and saved quotations on export?: {yesNo}");

if (query.IncludeObsolete == true)
{
Expand All @@ -46,17 +54,22 @@ public static void ShowOptionsMenu(CurrentQuery query)
Console.WriteLine($"Year Range: {query.StartYear} - {query.EndYear}");
}

Console.WriteLine("-------------------------");
Console.WriteLine("Toggle obsolete usage - O");
Console.WriteLine("Set date range: - D");
Console.WriteLine("Exit to main menu - X");
Console.WriteLine("----------------------------");
Console.WriteLine("Toggle obsolete usage - O");
Console.WriteLine("Delete old XML on Export - E");
Console.WriteLine("Set date range: - D");
Console.WriteLine("Exit to main menu - X");
var input = Console.ReadLine().Trim().ToLower();
switch (input)
{
case ("o" or "obsolete" or "ob"):
Console.WriteLine("Toggle Obsolete");
query.IncludeObsolete = false;
break;
case ("e" or "export" or "delete"):
SavedQueries.DeleteOnExport = true;
break;

case ("d" or "date" or "date range"):
Console.WriteLine("Enter Date Range");
(query.StartYear, query.EndYear) = SetYears(query);
Expand Down Expand Up @@ -130,8 +143,7 @@ static bool validate(string year) {
}
}
return (startYearInt, endYearInt);

}
}
}
}
}
}
4 changes: 0 additions & 4 deletions Quote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@ public class Quote
public string Text { get; set; }
public string Title { get; set; }
public string Author { get; set; }

}



}
100 changes: 95 additions & 5 deletions SavedQueries.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,105 @@
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Net;


namespace OxfordV2
{
public class SavedQueries
public static class SavedQueries
{
public string WordID { get; set; }
public List<Quote> Quotes { get; set; }
public static bool Instance { get; set; } = false;
public static bool DeleteOnExport { get; set; } = true;

public static string WordID { get; set; }
public static List<Quote> Quotes { get; set; }

public static string ExportFileName { get; set; } = "OED-export.xml";

static SavedQueries()
{
Instance=true;
Quotes = new();
}

public static void AddQuote(Quote quote) {
Quotes.Add(quote);
if (Quotes.Count == 1) {
Console.WriteLine($"{Quotes.Count} quote saved for export.");
}
else {
Console.WriteLine($"{Quotes.Count} quotes saved for export.");
}
}

public static void RenderXML() {
string xmlFile = Path.Combine(Environment.CurrentDirectory, ExportFileName);
File.Delete(xmlFile);
FileStream xmlFileStream = File.Create(xmlFile);

XmlWriter xml = XmlWriter.Create(xmlFileStream,
new XmlWriterSettings { Indent = true });

xml.WriteStartDocument();
xml.WriteStartElement("SuperMemoCollection");
int count = Quotes.Count;
xml.WriteElementString("Count", $"{count}");
// @TODO Add count number and ID number
for (int i = 0; i < Quotes.Count; i++) {
try {
xml.WriteStartElement("SuperMemoElement");
int ID = i + 1;
xml.WriteElementString("ID", $"{ID}");
xml.WriteElementString("Title", $"{Quotes[i].Author} - {Quotes[i].Year}");
xml.WriteElementString("Type", "Topic");
xml.WriteStartElement("Content");
xml.WriteElementString("Question", $"{Quotes[i].Text} --{Quotes[i].Author}, {Quotes[i].Year}");

string encoded = WebUtility.HtmlEncode("<H5 dir=ltr align=left><Font size=\"1\" style=\"color: transparent\"> SuperMemo Reference:</font><br><FONT class=reference>Title:\"My Test Quote\" <br>Source: Oxford English Dictionary");
xml.WriteElementString("SuperMemoReference", encoded);

xml.WriteEndElement();
xml.WriteEndElement();

}
catch (AggregateException ae)
{
var ex = ae.Flatten().InnerExceptions;
Console.WriteLine("Error writing XML document:");
foreach (var exception in ex)
{
Console.WriteLine($"{ex.ToString()}");
}
}
}

try {
xml.WriteEndElement();
xml.WriteEndDocument();
xml.Flush();

xml.Close();
xmlFileStream.Close();

Console.WriteLine("The XML file is saved here:");
Console.WriteLine(xmlFile);

public string ExportFileName { get; set; } = "OED-export.txt";

Trace.WriteLine("The contents of the exported XML file are:");
Trace.WriteLine(File.ReadAllText(xmlFile));
Console.WriteLine("Please press enter:..........");
Console.ReadLine();
}
catch (AggregateException ae)
{
var ex = ae.Flatten().InnerExceptions;
Console.WriteLine("Error exporting XML document:");
foreach (var exception in ex)
{
Console.WriteLine($"{ex.ToString()}");
}
}
}
}
}
Binary file modified bin/Debug/net5.0/OxfordV2.dll
Binary file not shown.
Binary file modified bin/Debug/net5.0/OxfordV2.pdb
Binary file not shown.
Binary file modified bin/Debug/net5.0/ref/OxfordV2.dll
Binary file not shown.
36 changes: 36 additions & 0 deletions logs/Log_OxfordApplication_20210502-1744.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Leaving Main method.
Starting Main Menu
In MainMenu()
Automatically looking up user entered word:
computer
Found that QueryMode is set to words.
Looking up the word:
computer
Now to call the words endpoint.
Getting request keys
resetHeaders called.
App Id is:
4ebc819b
Key is:
b6b1ca0e4e766b222d56c20f43c2396f
Here are the request Headers...
Accept: application/json
app_id: 4ebc819b
app_key: b6b1ca0e4e766b222d56c20f43c2396f

Calling the API
Called callWordsAPI
Making the request
Got responses.
Set JSONResponse to the response.
Left getWords task with the JSONResponse.
Parsing JSON
We now have the data as a string.
[{"id": "computer_nn01", "band": 9, "meta": {"created": 1891, "revised": true, "updated": 2008}, "lemma": "computer", "oed_url": "https://www.oed.com/view/Entry/37975#eid8618136", "daterange": {"end": null, "start": 1613, "obsolete": false, "rangestring": "1613\u2014"}, "etymology": {"etymons": [{"word": "compute", "language": "English", "target_id": "compute_vb01", "part_of_speech": "VB"}, {"word": "-er", "language": "English", "target_id": "er_su01", "part_of_speech": "SUFFIX"}], "etymology_type": "derivative", "etymon_language": [["English"]], "source_language": [["European languages", "Italic", "Latin"]], "etymology_summary": "Formed within English, by derivation."}, "first_use": "\u2018R. B.\u2019", "frequency": [[1750, 0.21], [1760, 0.18], [1770, 0.17], [1780, 0.16], [1790, 0.15], [1800, 0.14], [1810, 0.083], [1820, 0.077], [1830, 0.086], [1840, 0.086], [1850, 0.093], [1860, 0.11], [1870, 0.13], [1880, 0.16], [1890, 0.18], [1900, 0.21], [1910, 0.24], [1920, 0.45], [1930, 2.1], [1940, 10], [1950, 17], [1960, 40], [1970, 77], [1980, 110], [1990, 120], [2000, 120], [2010, 120]], "sense_ids": ["computer_nn01-8618138", "computer_nn01-8618177", "computer_nn01-130514973", "computer_nn01-130514976"], "definition": "An electronic device (or system of devices) which is used to store, manipulate, and communicate information, perform complex calculations, or control or regulate other devices or machines, and is capable of receiving information (data) and of processing it in accordance with variable procedural instructions (programs or software); esp. a small, self-contained one for individual use in the home or workplace, used esp. for handling text, images, music, and video, accessing and using the internet\u2026", "main_entry": true, "inflections": [{"region": "British", "inflections": [{"form": "computer", "part_of_speech": "NN"}, {"form": "computers", "part_of_speech": "NNS"}]}, {"region": "US", "inflections": [{"form": "computer", "part_of_speech": "NN"}, {"form": "computers", "part_of_speech": "NNS"}]}], "frequency_id": "computer_nn01-fq", "oed_reference": "computer, n.", "pronunciations": [{"ipa": ["k\u0259m\u02c8pju\u02d0t\u0259"], "region": "British"}, {"ipa": ["k\u0259m\u02c8pjud\u0259r"], "region": "US"}], "parts_of_speech": ["NN"], "primary_sense_id": "computer_nn01-130514973"}]
Extracted definition.
Set definition to query object.
Now to get and set the word ID.
The wordID was grabbed as:
computer_nn01The user's input was read as:
x
Exit selected.
59 changes: 59 additions & 0 deletions logs/Log_OxfordApplication_20210502-2343.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Leaving Main method.
Starting Main Menu
In MainMenu()
Automatically looking up user entered word:
cotton
Found that QueryMode is set to words.
Looking up the word:
cotton
Now to call the words endpoint.
Getting request keys
resetHeaders called.
App Id is:
4ebc819b
Key is:
b6b1ca0e4e766b222d56c20f43c2396f
Here are the request Headers...
Accept: application/json
app_id: 4ebc819b
app_key: b6b1ca0e4e766b222d56c20f43c2396f

Calling the API
Called callWordsAPI
Making the request
Got responses.
Set JSONResponse to the response.
Left getWords task with the JSONResponse.
Parsing JSON
We now have the data as a string.
[{"id": "cotton_nn01", "band": 8, "meta": {"created": 1893, "revised": false, "updated": null}, "lemma": "cotton", "oed_url": "https://www.oed.com/view/Entry/42480#eid8039299", "daterange": {"end": null, "start": 1400, "obsolete": false, "rangestring": "c1400\u2014"}, "etymology": {"etymons": [{"word": "coton", "language": "French"}], "etymology_type": "borrowing", "etymon_language": [["European languages", "Italic", "Romance", "Italo-Western", "Gallo-Romance", "French"]], "source_language": [["European languages", "Italic", "Romance", "Italo-Western", "Ibero-Romance", "Spanish"], ["Middle Eastern and Afro-Asiatic languages", "Afro-Asiatic", "Semitic", "Arabic"]], "etymology_summary": "A borrowing from French."}, "first_use": "Mandeville's Travels", "frequency": [[1750, 9.8], [1760, 12], [1770, 13], [1780, 15], [1790, 17], [1800, 20], [1810, 22], [1820, 25], [1830, 28], [1840, 30], [1850, 31], [1860, 32], [1870, 33], [1880, 36], [1890, 39], [1900, 40], [1910, 45], [1920, 50], [1930, 51], [1940, 49], [1950, 44], [1960, 36], [1970, 30], [1980, 24], [1990, 20], [2000, 19], [2010, 18]], "sense_ids": ["cotton_nn01-8039303", "cotton_nn01-8039415", "cotton_nn01-8039448", "cotton_nn01-8039461", "cotton_nn01-8039500", "cotton_nn01-8039549", "cotton_nn01-8039616", "cotton_nn01-8039644", "cotton_nn01-8039733", "cotton_nn01-8039754", "cotton_nn01-8039812", "cotton_nn01-8039830", "cotton_nn01-8039844"], "definition": "The white fibrous substance, soft and downy like wool, which clothes the seeds of the cotton-plant (Gossypium); used (more extensively than any other material) for making cloth and thread, and for various purposes in the arts.", "main_entry": true, "inflections": [{"region": "British", "inflections": [{"form": "cotton", "part_of_speech": "NN"}, {"form": "cottons", "part_of_speech": "NNS"}]}, {"region": "US", "inflections": [{"form": "cotton", "part_of_speech": "NN"}, {"form": "cottons", "part_of_speech": "NNS"}]}], "frequency_id": "cotton_nn01-fq", "oed_reference": "cotton, n.1", "pronunciations": [{"ipa": ["\u02c8k\u0252tn"], "region": "British"}, {"ipa": ["\u02c8k\u0251tn"], "region": "US"}], "parts_of_speech": ["NN"], "primary_sense_id": "cotton_nn01-8039303"}]
Extracted definition.
Set definition to query object.
Now to get and set the word ID.
The wordID was grabbed as:
cotton_nn01The user's input was read as:
q
Get quotaions based on word selected.
API.cs is starting quotations mode.
Getting request keys
resetHeaders called.
App Id is:
4ebc819b
Key is:
b6b1ca0e4e766b222d56c20f43c2396f
Here are the request Headers...
Accept: application/json
app_id: 4ebc819b
app_key: b6b1ca0e4e766b222d56c20f43c2396f

Called callQuotationsAPI
Got quotation responses.
Set JSONResponse to the response.
Ran quotations synchronously.
Parsing quotations JSON.
First quote grabbed as:

In MainMenu()
The user's input was read as:
x
Exit selected.
Loading

0 comments on commit 09bf80c

Please sign in to comment.