Skip to content

Commit e7085a3

Browse files
committed
option to read a list of page titles from a file
1 parent a97e851 commit e7085a3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

import_logs.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,11 @@ def _create_parser(self):
764764
"changed General.action_title_category_delimiter in your Matomo configuration, you need to set this "
765765
"option to the same value in order to get a pretty page titles report."
766766
)
767+
option_parser.add_option(
768+
'--page-titles-from', dest='page_titles_from', default=None,
769+
help="Loads a mapping of URLs to page titles from a given file so that titles can be displayed "
770+
"in the page titles report."
771+
)
767772
option_parser.add_option(
768773
'--dump-log-regex', dest='dump_log_regex', action='store_true', default=False,
769774
help="Prints out the regex string used to parse log lines and exists. Can be useful for using formats "
@@ -923,6 +928,15 @@ def _parse_args(self, option_parser):
923928
else:
924929
logging.debug('Accepted hostnames: all')
925930

931+
self.page_titles_map = {}
932+
933+
if self.options.page_titles_from:
934+
for line in open(self.options.page_titles_from).readlines():
935+
separator = line.index('=')
936+
url = line[0:separator].strip()
937+
title = line[separator+1:-1].strip()
938+
self.page_titles_map[url] = title
939+
926940
if self.options.log_format_regex:
927941
self.format = RegexFormat('custom', self.options.log_format_regex, self.options.log_date_format)
928942
elif self.options.log_format_name:
@@ -1908,6 +1922,10 @@ def _get_hit_args(self, hit):
19081922
urllib.quote(args['urlref'], '')
19091923
) if args['urlref'] != '' else '')
19101924
)
1925+
else:
1926+
page_title = config.page_titles_map.get(args['url'])
1927+
if page_title:
1928+
args['action_name'] = page_title
19111929

19121930
if hit.generation_time_milli > 0:
19131931
args['gt_ms'] = int(hit.generation_time_milli)

0 commit comments

Comments
 (0)