Example #1
0
        public static void GenerateComic(DateTime currentDate)
        {
            var csv = new CsvReader(new StreamReader(dataFilePath));

            var config = new CsvHelper.Configuration.Configuration();

            config.AutoMap <CrimeRecord>();

            var records = csv.GetRecords <CrimeRecord>().Where(r => r.OccFrom.Month == currentDate.Month && r.OccFrom.Day == currentDate.Day).ToArray();

            var allowedKeywords = File.ReadAllText("comic/keywords.txt"); //must be present

            var keywords = records.Select(s => s.KeyWord).Where(s => allowedKeywords.Contains(s)).Distinct().ToArray();

            var selectedKeyword = keywords[rnd.Next(0, keywords.Count() - 1)];

            var splitChars = new[] { ';', '/' };

            var tokens = selectedKeyword.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);

            selectedKeyword = tokens[0];

            print($"Theme:{selectedKeyword}");

            var crimes = records.Where(r => r.KeyWord.Contains(selectedKeyword)).ToArray();

            print($"related crimes:{crimes.Length}");
            var crime = crimes[rnd.Next(0, crimes.Length - 1)];

            foreach (var kv in scenes)
            {
                AddScene(kv, crime);
            }

            ComicGen gen = new ComicGen();

            if (!Directory.Exists("result"))
            {
                Directory.CreateDirectory("result");
            }
            WriteComic(gen.Generate("", messages), $"result/comic_{currentDate.Ticks}.png");
        }
Example #2
0
		static void Main ( string[] a_args )
		{
			string outPath = null;
			string packName = null;
			var messages = new List<ComicGen.Message> ();
			ulong userId = 0;

			bool readUser = true;
			foreach ( var arg in a_args )
			{
				if ( outPath == null )
				{
					outPath = arg;
					continue;
				}

				if ( packName == null )
				{
					packName = arg;
					continue;
				}

				if ( readUser )
				{
					try
					{
						userId = Convert.ToUInt64 ( arg );
					}
					catch
					{
						Console.WriteLine ( "ERR: Arg isn't a number." );
						Environment.Exit ( -1 );
					}
					readUser = false;
				}
				else
				{
					var msg = new ComicGen.Message ( userId, arg );
					messages.Add ( msg ); 
					readUser = true;
				}
			}

			if ( outPath == null || packName == null || messages.Count == 0 )
			{
				Console.WriteLine ( "ERR: Bag arg ranges." );
				Environment.Exit ( -1 );
			}

			ComicGen gen = new ComicGen ();
			var ms = gen.Generate ( packName, messages );
			if ( ms == null )
			{
				Console.WriteLine ( "ERR: Failed to generate comic." );
				Environment.Exit ( -2 );
			}

			try
			{
				var fs = File.Open ( outPath, FileMode.Create );
				ms.CopyTo ( fs );
				ms.Close ();
				fs.Close ();
			}
			catch ( IOException e )
			{
				Console.WriteLine ( "ERR: Failed to write comic to disk." );
				Console.WriteLine ( e );
			}
		}