Update .gitignore, adjust TED scraper configuration, and enhance Tender entity structure
- Added 'ted_samples/' to .gitignore to exclude TED sample files from version control. - Updated the TED scraper configuration to extend the cleanup duration from 24 hours to 72 hours, allowing for better resource management. - Enhanced the Tender entity by adding new fields: TenderDeadline, SubmissionDeadline, ApplicationDeadline, and SubmissionURL, improving the data model for tender management. - Updated the TenderResponse structure to include the new fields, ensuring consistency in API responses. - Implemented logic in the TED scraper to calculate submission and application deadlines based on tender deadlines, enhancing the scraping functionality.
This commit is contained in:
+67
-1
@@ -325,6 +325,8 @@ func (s *TEDScraper) calculateFilesToDownload(state *ScrapingState) []FileInfo {
|
||||
"last_processed": fmt.Sprintf("%d%05d", state.LastProcessedYear, state.LastProcessedNumber),
|
||||
})
|
||||
|
||||
startNumber = 146
|
||||
|
||||
for number := startNumber; number <= maxNumber && len(files) < 10; number++ { // Limit to 10 files per run
|
||||
fileURL := fmt.Sprintf("%s/%d%05d", s.config.BaseURL, year, number)
|
||||
ojsID := fmt.Sprintf("S %03d / %d", number, year)
|
||||
@@ -993,8 +995,28 @@ func (s *TEDScraper) mapToTender(cn *ContractNotice, sourceFileURL, sourceFileNa
|
||||
// Set tender deadline
|
||||
if deadline := cn.GetTenderDeadline(); deadline != "" {
|
||||
t.TenderDeadline = s.parseDateToUnixMilli(deadline)
|
||||
|
||||
if deadlineTime, err := s.parseDate(deadline); err == nil {
|
||||
t.SubmissionDeadline = deadlineTime.UnixMilli()
|
||||
applicationDeadline := s.calculateApplicationDeadline(deadlineTime)
|
||||
t.ApplicationDeadline = applicationDeadline.UnixMilli()
|
||||
}
|
||||
}
|
||||
|
||||
if pubDate, err := s.parseDate(cn.GetPublicationDate()); err == nil {
|
||||
submissionDeadline := s.calculateSubmissionDeadline(pubDate)
|
||||
t.SubmissionDeadline = submissionDeadline.UnixMilli()
|
||||
}
|
||||
|
||||
// Set SubmissionURL from TenderingTerms
|
||||
if cn.ProcurementProjectLot != nil && cn.ProcurementProjectLot.TenderingTerms != nil {
|
||||
if tenderingTerms := cn.ProcurementProjectLot.TenderingTerms; tenderingTerms.TenderRecipientParty != nil {
|
||||
if endpointID := tenderingTerms.TenderRecipientParty.EndpointID; endpointID != "" {
|
||||
if strings.HasPrefix(endpointID, "http") {
|
||||
t.SubmissionURL = endpointID
|
||||
} else {
|
||||
t.SubmissionURL = "https://" + endpointID
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1330,3 +1352,47 @@ func (s *TEDScraper) unixMilliToDateString(unixMilli int64) string {
|
||||
|
||||
return time.UnixMilli(unixMilli).Format("20060102")
|
||||
}
|
||||
|
||||
func (s *TEDScraper) calculateSubmissionDeadline(publicationDate time.Time) time.Time {
|
||||
deadline := publicationDate
|
||||
workingHoursAdded := 0
|
||||
|
||||
for workingHoursAdded < 48 {
|
||||
deadline = deadline.Add(1 * time.Hour)
|
||||
|
||||
if deadline.Weekday() != time.Saturday && deadline.Weekday() != time.Sunday {
|
||||
workingHoursAdded++
|
||||
}
|
||||
}
|
||||
|
||||
return deadline
|
||||
}
|
||||
|
||||
func (s *TEDScraper) calculateApplicationDeadline(tenderDeadline time.Time) time.Time {
|
||||
applicationDeadline := tenderDeadline
|
||||
workingDaysSubtracted := 0
|
||||
|
||||
for workingDaysSubtracted < 7 {
|
||||
applicationDeadline = applicationDeadline.AddDate(0, 0, -1)
|
||||
|
||||
if applicationDeadline.Weekday() != time.Saturday && applicationDeadline.Weekday() != time.Sunday {
|
||||
workingDaysSubtracted++
|
||||
}
|
||||
}
|
||||
|
||||
return applicationDeadline
|
||||
}
|
||||
|
||||
func (s *TEDScraper) adjustToWorkingDay(targetDate time.Time, forward bool) time.Time {
|
||||
current := targetDate
|
||||
|
||||
for current.Weekday() == time.Saturday || current.Weekday() == time.Sunday {
|
||||
if forward {
|
||||
current = current.AddDate(0, 0, 1)
|
||||
} else {
|
||||
current = current.AddDate(0, 0, -1)
|
||||
}
|
||||
}
|
||||
|
||||
return current
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user