<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk:443/22116/index.php?action=history&amp;feed=atom&amp;title=Example_code_-_Dicts</id>
	<title>Example code - Dicts - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk:443/22116/index.php?action=history&amp;feed=atom&amp;title=Example_code_-_Dicts"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22116/index.php?title=Example_code_-_Dicts&amp;action=history"/>
	<updated>2026-04-24T15:17:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22116/index.php?title=Example_code_-_Dicts&amp;diff=187&amp;oldid=prev</id>
		<title>WikiSysop: /* Example of a log entry */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22116/index.php?title=Example_code_-_Dicts&amp;diff=187&amp;oldid=prev"/>
		<updated>2025-09-03T11:31:44Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Example of a log entry&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:31, 3 September 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l7&quot;&gt;Line 7:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Example of a log entry ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Example of a log entry ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This is one line split in 3, so it can be seen.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This is one line split in 3, so it can be seen&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. If your screen is not wide enough, the lines may break further&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt;52d3ccde.dynamic-ip.k-net.dk&amp;lt;/span&amp;gt; - - [07/Mar/2017:19:48:44 +0100] &amp;quot;GET &amp;lt;span style=&amp;quot;color:#00FF00&amp;quot;&amp;gt;/teaching/index.php?title=-&amp;amp;action=raw&amp;amp;gen=js&amp;amp;useskin=monobook&amp;lt;/span&amp;gt; HTTP/1.1&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt;52d3ccde.dynamic-ip.k-net.dk&amp;lt;/span&amp;gt; - - [07/Mar/2017:19:48:44 +0100] &amp;quot;GET &amp;lt;span style=&amp;quot;color:#00FF00&amp;quot;&amp;gt;/teaching/index.php?title=-&amp;amp;action=raw&amp;amp;gen=js&amp;amp;useskin=monobook&amp;lt;/span&amp;gt; HTTP/1.1&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     200 290 &amp;quot;http://wiki.bio.dtu.dk/teaching/index.php/Course27617Spring2017&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     200 290 &amp;quot;http://wiki.bio.dtu.dk/teaching/index.php/Course27617Spring2017&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key c22116:diff:1.41:old-186:rev-187:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22116/index.php?title=Example_code_-_Dicts&amp;diff=186&amp;oldid=prev</id>
		<title>WikiSysop: Created page with &quot;__NOTOC__ == Files used in example == [https://teaching.healthtech.dtu.dk/material/22116/apachewiki.log Log from web server]  == Web server statistics == It is of interest to the BOSS to see how many visitors a web site has and how many web pages has been seen. So therefore someone (you) has to make some statistics from the web server log file.  == Example of a log entry == This is one line split in 3, so it can be seen.  &lt;span style=&quot;color:#FF0000&quot;&gt;52d3ccde.dynamic-ip.k...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22116/index.php?title=Example_code_-_Dicts&amp;diff=186&amp;oldid=prev"/>
		<updated>2025-09-03T11:30:47Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ == Files used in example == [https://teaching.healthtech.dtu.dk/material/22116/apachewiki.log Log from web server]  == Web server statistics == It is of interest to the BOSS to see how many visitors a web site has and how many web pages has been seen. So therefore someone (you) has to make some statistics from the web server log file.  == Example of a log entry == This is one line split in 3, so it can be seen.  &amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt;52d3ccde.dynamic-ip.k...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
== Files used in example ==&lt;br /&gt;
[https://teaching.healthtech.dtu.dk/material/22116/apachewiki.log Log from web server]&lt;br /&gt;
&lt;br /&gt;
== Web server statistics ==&lt;br /&gt;
It is of interest to the BOSS to see how many visitors a web site has and how many web pages has been seen. So therefore someone (you) has to make some statistics from the web server log file.&lt;br /&gt;
&lt;br /&gt;
== Example of a log entry ==&lt;br /&gt;
This is one line split in 3, so it can be seen.&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt;52d3ccde.dynamic-ip.k-net.dk&amp;lt;/span&amp;gt; - - [07/Mar/2017:19:48:44 +0100] &amp;quot;GET &amp;lt;span style=&amp;quot;color:#00FF00&amp;quot;&amp;gt;/teaching/index.php?title=-&amp;amp;action=raw&amp;amp;gen=js&amp;amp;useskin=monobook&amp;lt;/span&amp;gt; HTTP/1.1&amp;quot;&lt;br /&gt;
    200 290 &amp;quot;http://wiki.bio.dtu.dk/teaching/index.php/Course27617Spring2017&amp;quot;&lt;br /&gt;
    &amp;quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0.2 Safari/602.3.12&amp;quot;&lt;br /&gt;
In this example, we are only interested in the &amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt; red part &amp;lt;/span&amp;gt;, which is the IP-number or host name of the visitor, and the &amp;lt;span style=&amp;quot;color:#00FF00&amp;quot;&amp;gt; green part&amp;lt;/span&amp;gt;, which is the file served to the visitor.&lt;br /&gt;
The problem is that the web is filled with search engines indexing the web sites, and they don&amp;#039;t count as humans - yet. So they must be excluded from your statistics. Most of the indexing robots look at a file called /robots.txt, for what they are allowed to index. So here is a way to identify the non-humans.&lt;br /&gt;
Also, many web pages uses pictures, meaning that the web server also serves picture files to the visitors. These pictures do not count as a page view (since they are being part of a page). Picture files mostly have the extensions .gif, .jpg, .png and .jpeg, so they can also be identified.&lt;br /&gt;
&lt;br /&gt;
== The program ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# makes statistics on a apache webserver log file&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
# get file&lt;br /&gt;
try:&lt;br /&gt;
    logfile = open(&amp;#039;apachewiki.log&amp;#039;, &amp;#039;r&amp;#039;)&lt;br /&gt;
except IOError as err:&lt;br /&gt;
    print(&amp;#039;There seems to be a problem with the file:&amp;#039;, str(err))&lt;br /&gt;
    sys.exit(1)&lt;br /&gt;
&lt;br /&gt;
# Dict for counting page views&lt;br /&gt;
hosts = dict()&lt;br /&gt;
# Set of search engine crawlers&lt;br /&gt;
crawler = set()&lt;br /&gt;
&lt;br /&gt;
for line in logfile:&lt;br /&gt;
    field = line.split()&lt;br /&gt;
    # Is this a crawler&lt;br /&gt;
    if field[6] == &amp;#039;/robots.txt&amp;#039;:&lt;br /&gt;
        crawler.add(field[0])&lt;br /&gt;
    # Is this a pic?&lt;br /&gt;
    if not field[6].endswith((&amp;#039;.gif&amp;#039;,&amp;#039;.jpg&amp;#039;,&amp;#039;.png&amp;#039;,&amp;#039;.jpeg&amp;#039;)):&lt;br /&gt;
        # Must be a page view then&lt;br /&gt;
        if field[0] in hosts:&lt;br /&gt;
            hosts[field[0]] += 1&lt;br /&gt;
        else:&lt;br /&gt;
            hosts[field[0]] = 1&lt;br /&gt;
&lt;br /&gt;
logfile.close()&lt;br /&gt;
&lt;br /&gt;
# Remove page views made by crawlers&lt;br /&gt;
crawlCount = 0&lt;br /&gt;
for item in crawler:&lt;br /&gt;
    crawlCount += hosts[item]&lt;br /&gt;
    del hosts[item]&lt;br /&gt;
&lt;br /&gt;
# Sort page views by size&lt;br /&gt;
# Print top ten&lt;br /&gt;
print(&amp;#039;Top 10 viewers&amp;#039;)&lt;br /&gt;
for host in sorted(hosts.keys(), reverse=True, key=hosts.get)[:10]:&lt;br /&gt;
    print(host, hosts[host])&lt;br /&gt;
# Get total page views&lt;br /&gt;
total = 0&lt;br /&gt;
for val in list(hosts.values()):&lt;br /&gt;
    total += val&lt;br /&gt;
print(&amp;#039;Unique visitors:&amp;#039;, len(hosts))&lt;br /&gt;
print(&amp;#039;Unique crawlers:&amp;#039;, len(crawler))&lt;br /&gt;
print(&amp;#039;Total visitor page views:&amp;#039;, total)&lt;br /&gt;
print(&amp;#039;Total crawler page views:&amp;#039;, crawlCount)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>