Révision 8a509595
Ajouté par Julien Enselme il y a presque 11 ans
scripts_divers/migrer_taches_vers_redmine/url_parser.py | ||
---|---|---|
1 | 1 |
#!/usr/share/env python3 |
2 | 2 |
|
3 | 3 |
from html.parser import HTMLParser |
4 |
import httplib2 |
|
4 | 5 |
|
5 |
SITE_URL = 'http://assos.centrale-marseille.fr' |
|
6 | 6 |
|
7 | 7 |
class LinksParser(HTMLParser): |
8 | 8 |
def __init__(self): |
... | ... | |
31 | 31 |
if self.recording: |
32 | 32 |
self.data.append(data) |
33 | 33 |
|
34 |
def give_nids(): |
|
34 |
def give_nids(url):
|
|
35 | 35 |
p = LinksParser() |
36 |
h = httplib2.Http() |
|
36 | 37 |
|
37 |
with open('tache.html', 'r') as input: |
|
38 |
p.feed(input.read()) |
|
38 |
resp, content = h.request(url, 'GET') |
|
39 |
text = content.decode('utf-8') |
|
40 |
|
|
41 |
p.feed(text) |
|
39 | 42 |
return p.data |
40 | 43 |
|
41 |
def give_urls(nids): |
|
44 |
def give_json_urls(url, base_url): |
|
45 |
nids = give_nids(url) |
|
42 | 46 |
tache_urls = [] |
43 | 47 |
for nid in nids: |
44 |
tache_urls.append(SITE_URL + '/node/' + nid) |
|
45 |
return tache_urls |
|
48 |
tache_urls.append(base_url + '/node/' + nid + '.json') |
|
49 |
return nids, tache_urls |
Formats disponibles : Unified diff
On utilise désormais les modules drupal entity_json (pour la liste des commentaires)
et restws (pour récupérer le contenu des nodes et des commentaires)