mirror of
				https://github.com/KevinMidboe/miljobilen-rss.git
				synced 2025-10-29 17:50:23 +00:00 
			
		
		
		
	Folloren updated datestring on website, this fixes (#2)
Folloren has a new structure for the new year! They changed it from `(\d.\d)` to `(\d. [a-z])`.
This commit is contained in:
		| @@ -85,8 +85,8 @@ function getTimeForLocation(text, location) { | |||||||
|  */ |  */ | ||||||
| function getDatesForLocation(text, location) { | function getDatesForLocation(text, location) { | ||||||
|   const regexpDatesString = new RegExp( |   const regexpDatesString = new RegExp( | ||||||
|     `${location}.*<br>((\\d+.\\d+).*)</p>`, |     `${location}.*<br>((\\d+. [a-z– ]+).*)</p>`, | ||||||
|     "i" |     "gmi" | ||||||
|   ); |   ); | ||||||
|   let datesStringMatches = text.match(regexpDatesString); |   let datesStringMatches = text.match(regexpDatesString); | ||||||
|  |  | ||||||
| @@ -97,7 +97,7 @@ function getDatesForLocation(text, location) { | |||||||
|   // TODO make regex stop at first capture |   // TODO make regex stop at first capture | ||||||
|   const datesString = datesStringMatches?.[0]?.split("</p>")?.[0]; |   const datesString = datesStringMatches?.[0]?.split("</p>")?.[0]; | ||||||
|  |  | ||||||
|   const regexpDates = /(\d+\.\d+)+/g; |   const regexpDates = /(\d+. [a-z]+)+/g; | ||||||
|   const dates = String(datesString)?.match(regexpDates); |   const dates = String(datesString)?.match(regexpDates); | ||||||
|  |  | ||||||
|   if (dates == null || dates?.length === 0) |   if (dates == null || dates?.length === 0) | ||||||
|   | |||||||
							
								
								
									
										31
									
								
								src/utils.js
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								src/utils.js
									
									
									
									
									
								
							| @@ -8,6 +8,20 @@ These are the available arguments: | |||||||
|     print       Prints results |     print       Prints results | ||||||
|     help        Prints this message`; |     help        Prints this message`; | ||||||
|  |  | ||||||
|  | const monthStrings = [ | ||||||
|  |   "jan", | ||||||
|  |   "feb", | ||||||
|  |   "mars", | ||||||
|  |   "apr", | ||||||
|  |   "mai", | ||||||
|  |   "juni", | ||||||
|  |   "juli", | ||||||
|  |   "sept", | ||||||
|  |   "okt", | ||||||
|  |   "nov", | ||||||
|  |   "des", | ||||||
|  | ]; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Converts string DD.MM to JS date object. |  * Converts string DD.MM to JS date object. | ||||||
|  * @param {string} dateString |  * @param {string} dateString | ||||||
| @@ -15,15 +29,16 @@ These are the available arguments: | |||||||
|  */ |  */ | ||||||
| function websiteDateToTime(dateString) { | function websiteDateToTime(dateString) { | ||||||
|   const date = new Date(); |   const date = new Date(); | ||||||
|   const dayAndMonthString = dateString?.match(/(\d+).(\d+)/); |   const dayAndMonthString = dateString?.match(/(\d+)(. )([a-z]+)/); | ||||||
|  |  | ||||||
|   if (dayAndMonthString == null || dayAndMonthString.length < 3) |   if (dayAndMonthString == null || dayAndMonthString.length < 4) | ||||||
|     throw new Error("Unable to created string from unparsable date."); |     throw new Error("Unable to created string from unparsable date."); | ||||||
|  |  | ||||||
|   const day = Number(dayAndMonthString[1]); |   const day = Number(dayAndMonthString[1]); | ||||||
|   const month = Number(dayAndMonthString[2]); |   const monthIndex = monthStrings.findIndex(m => m === dayAndMonthString[3]) | ||||||
|  |   const month = Number(monthIndex); | ||||||
|  |  | ||||||
|   date.setMonth(Number(month - 1)); |   date.setMonth(Number(month)); | ||||||
|   date.setDate(Number(day)); |   date.setDate(Number(day)); | ||||||
|  |  | ||||||
|   return date; |   return date; | ||||||
| @@ -58,11 +73,11 @@ function timeToWebsiteDate(date) { | |||||||
|  */ |  */ | ||||||
| function validateArguments(place, lookAhead) { | function validateArguments(place, lookAhead) { | ||||||
|   const placeUndefined = place === undefined; |   const placeUndefined = place === undefined; | ||||||
|   const help = (place === "-h" || place === "--help") |   const help = place === "-h" || place === "--help"; | ||||||
|   const numberIsNotNumber = isNaN(Number(lookAhead)) |   const numberIsNotNumber = isNaN(Number(lookAhead)); | ||||||
|   const validation = [placeUndefined, help, numberIsNotNumber] |   const validation = [placeUndefined, help, numberIsNotNumber]; | ||||||
|  |  | ||||||
|   if (!validation.every(v => v === false)) { |   if (!validation.every((v) => v === false)) { | ||||||
|     console.log(HELP_TEXT); |     console.log(HELP_TEXT); | ||||||
|     process.exit(0); |     process.exit(0); | ||||||
|   } |   } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user