Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tools2/create_low_rank_pages.py
blob: 2227e9986e21018b23c30f14e89cc165cee9f3c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Create a file with a list of pages with less than N links pointing to them.
# By default N=5 but can be configured with the param --min_cant_links

import codecs
import sys
from make_selection import FileListReader
import config

if __name__ == '__main__':

    input_xml_file_name = config.input_xml_file_name

    min_cant_links = 5
    if len(sys.argv) > 1:
        if sys.argv[1] == '--min_cant_links':
            min_cant_links = int(sys.argv[2])

    print "Adding articles with less than %d links" % min_cant_links

    # Read favorites list
    favorites_reader = FileListReader(config.favorites_file_name)

    ranking_file = codecs.open('%s.links_counted' % input_xml_file_name,
                            encoding='utf-8', mode='r')

    print "Writing low_rank_pages file"
    output_file = codecs.open('%s.low_rank_pages' % input_xml_file_name,
                    encoding='utf-8', mode='w')

    line = ranking_file.readline()
    while line:
        parts = line.split()
        article = parts[0]
        cant_links = int(parts[1])
        if cant_links < min_cant_links and \
                article not in favorites_reader.list:
            output_file.write('%s\n' % article)

        line = ranking_file.readline()

    output_file.close()
    ranking_file.close()