Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SAE203
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ZHANG David
SAE203
Commits
5f64d54b
Commit
5f64d54b
authored
3 years ago
by
ZHANG David
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
84ffc58b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
aggreg.py
+126
-0
126 additions, 0 deletions
aggreg.py
with
126 additions
and
0 deletions
aggreg.py
0 → 100644
+
126
−
0
View file @
5f64d54b
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue May 24 22:10:59 2022
@author: z21204242
"""
import
feedparser
import
sys
from
datetime
import
datetime
def
charge_urls
(
liste_url
):
res
=
[]
for
i
in
range
(
1
,
len
(
liste_url
)):
news_feed
=
feedparser
.
parse
(
liste_url
[
i
])
res
.
append
(
news_feed
)
return
res
def
fusion_flux
(
liste_url
,
liste_flux
):
sortie
=
[]
for
i
in
range
(
0
,
len
(
liste_flux
)):
doc_rss
=
liste_flux
[
i
]
dicto
=
{}
dicto
[
'
Titre
'
]
=
doc_rss
[
'
entries
'
][
0
][
'
title
'
]
dicto
[
'
categorie
'
]
=
doc_rss
[
'
entries
'
][
0
][
'
tags
'
][
0
][
'
term
'
]
dicto
[
'
serveur
'
]
=
doc_rss
[
'
feed
'
][
'
link
'
]
dicto
[
'
date_publi
'
]
=
doc_rss
[
'
entries
'
][
0
][
'
published
'
]
dicto
[
'
lien
'
]
=
doc_rss
[
'
entries
'
][
0
][
'
link
'
]
dicto
[
'
description
'
]
=
doc_rss
[
'
entries
'
][
0
][
'
summary
'
]
dicto
[
'
guid
'
]
=
doc_rss
[
'
entries
'
][
0
][
'
id
'
]
sortie
.
append
(
dicto
)
return
sortie
def
genere_html
(
liste_evenements
,
chemin_html
):
for
i
in
range
(
0
,
len
(
liste_evenements
)):
date_actu
=
datetime
.
today
().
strftime
(
'
%Y-%m-%d %H:%M
'
)
title
=
liste_evenements
[
i
][
'
Titre
'
]
serveur
=
liste_evenements
[
i
][
'
serveur
'
]
pubDate
=
liste_evenements
[
i
][
'
date_publi
'
]
category
=
liste_evenements
[
i
][
'
categorie
'
]
link
=
liste_evenements
[
i
][
'
lien
'
]
guid
=
liste_evenements
[
i
][
'
guid
'
]
description
=
liste_evenements
[
i
][
'
description
'
]
file
=
open
(
chemin_html
,
'
w
'
)
html_code
=
f
"""
<!DOCTYPE html>
<html lang=
"
en
"
>
<head>
<meta charset=
"
utf-8
"
>
<meta name=
"
viewport
"
content=
"
width=device-width, initial-scale=1
"
>
<title>Events log</title>
<link rel=
"
stylesheet
"
href=
"
css/feed.css
"
type=
"
text/css
"
/>
</head>
<body>
<article>
<header>
<h1>Events log</h1>
</header>
<p>
{
date_actu
}
</p>
<!-- liste des événements (items du flux RSS). Un bloc <article> par item dans le flux -->
<article>
<header>
<h2>
{
title
}
</h2>
</header>
<p>
{
serveur
}
</p>
<p>
{
pubDate
}
</p>
<p>
{
category
}
</p>
<p>
{
guid
}
</p>
<p><a href=
"
{
link
}
"
>
{
link
}
</a></p>
<p>
{
description
}
</p>
</article>
<!-- etc. si autres articles -->
</article>
</body>
</html>
"""
html_code
.
format
(
date_actu
=
date_actu
,
title
=
title
,
serveur
=
serveur
,
pubDate
=
pubDate
,
category
=
category
,
link
=
link
,
guid
=
guid
,
description
=
description
)
file
.
write
(
html_code
)
file
.
close
def
main
():
liste_url
=
sys
.
argv
res
=
charge_urls
(
liste_url
)
liste_flux
=
res
fusion_flux
(
liste_url
,
liste_flux
)
sortie
=
fusion_flux
(
liste_url
,
liste_flux
)
for
news_feed
in
res
:
print
(
news_feed
[
'
feed
'
].
keys
())
print
(
'
-
'
*
60
)
print
()
print
(
"
Titre :
"
,
news_feed
[
'
feed
'
][
'
title
'
])
print
(
"
Sous-titre :
"
,
news_feed
[
'
feed
'
][
'
subtitle
'
])
print
(
"
Lien vers le flux :
"
,
news_feed
[
'
feed
'
][
'
link
'
])
print
()
print
(
"
nombre d
'
actualités publiées:
"
,
len
(
news_feed
[
'
entries
'
]))
print
()
# propriétés de chaque item du flux
print
(
news_feed
[
'
entries
'
][
0
].
keys
())
print
(
'
-
'
*
60
)
print
()
for
entry
in
news_feed
.
entries
:
print
(
f
"
{
entry
[
'
title
'
]
}
-->
{
entry
[
'
link
'
]
}
"
)
chemin_html
=
"
/amuhome/z21204242/Bureau/page_html.html
"
liste_evenements
=
sortie
genere_html
(
liste_evenements
,
chemin_html
)
print
(
liste_evenements
)
if
__name__
==
'
__main__
'
:
main
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment