Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp21
- {
- class Program
- {
- static Random rnd = new Random();
- static void Main(string[] args)
- {
- List<string> lines = new List<string>();
- string inputPath = @"INPUT_DIRECTORY\urls.txt";
- string outputPath = @"OUTPUT_DIRECTORY\MySources.xml";
- using (StreamReader sr = new StreamReader(inputPath))
- {
- string line;
- while ((line = sr.ReadLine()) != null)
- {
- lines.Add(line);
- }
- }
- string xml = "";
- int counter = 1;
- for (int i = 0; i < lines.Count; i += 2)
- {
- string URL = lines.ElementAt(i);
- string Title = lines.ElementAt(i + 1);
- Uri uri = new Uri(URL);
- string InternetSiteTitle = uri.Host;
- string Year = "2019";
- string YearAccessed = "2019";
- var month = rnd.Next(4, 6);
- string MonthAccessed = month.ToString();
- int start, end;
- if (month == 4)
- {
- start = 1;
- end = 29;
- }
- else
- {
- start = 1;
- end = 19;
- }
- var day = rnd.Next(start, end);
- string DayAccessed = day.ToString();
- string Tag = "SomeTag" + counter;
- string xmlNode = $"<b:Source> <b:Tag>{Tag}</b:Tag> <b:SourceType>InternetSite</b:SourceType> <b:Guid>" + "{044F29E4-974C-42F2-9B2D-DA1E893E51AD}" + $"</b:Guid> <b:Title>{Title}</b:Title> <b:InternetSiteTitle>{InternetSiteTitle}</b:InternetSiteTitle> <b:Year>{Year}</b:Year> <b:YearAccessed>{YearAccessed}</b:YearAccessed> <b:MonthAccessed>{MonthAccessed}</b:MonthAccessed> <b:DayAccessed>{DayAccessed}</b:DayAccessed> <b:URL>{URL}</b:URL> </b:Source>";
- xml += xmlNode;
- if (counter % 3 == 0)
- {
- xml = "<b:Sources SelectedStyle=\"\" xmlns:b=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\" xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\"> " + xml + " </b:Sources>";
- outputPath = $@"C:\Users\zgame\Desktop\src2\MySources{counter}.xml";
- using (StreamWriter sr = new StreamWriter(outputPath))
- {
- sr.Write(xml);
- }
- xml = "";
- }
- counter++;
- }
- outputPath = @"C:\Users\zgame\Desktop\MySources.xml";
- xml = "<b:Sources SelectedStyle=\"\" xmlns:b=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\" xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\"> " + xml + " </b:Sources>";
- using (StreamWriter sr = new StreamWriter(outputPath))
- {
- sr.Write(xml);
- }
- Console.WriteLine("Success");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement