SHOW:
|
|
- or go back to the newest paste.
1 | import requests as r | |
2 | import subprocess as sub | |
3 | ||
4 | #http://www.jeuxvideo.com/forums/0-51-0-1-0-1-0-blabla-18-25-ans.htm | |
5 | ||
6 | def get(url): | |
7 | return r.get(url).content.decode('utf-8') | |
8 | ||
9 | def save(filename, data): | |
10 | with open(filename, 'a') as f: | |
11 | f.write(data) | |
12 | ||
13 | def get_clip(): | |
14 | p = sub.Popen(['xclip','-selection', 'clipboard', '-o'], stdout=sub.PIPE) | |
15 | retcode = p.wait() | |
16 | return p.stdout.read() | |
17 | ||
18 | ||
19 | domain = "http://www.jeuxvideo.com" | |
20 | url = "http://www.jeuxvideo.com/profil/" | |
21 | fav = "?mode=favoris" | |
22 | ||
23 | user = get_clip().decode('utf-8').lower() | |
24 | ||
25 | if not 'http://' in user: | |
26 | user = user.split('\n')[0].strip() | |
27 | else: | |
28 | user = user.split(url)[1].split('?')[0] | |
29 | ||
30 | url = url + user + fav | |
31 | ||
32 | print(url) | |
33 | ||
34 | start_tag = '<li><a href="//' | |
35 | data = str(get(url)).split(start_tag) | |
36 | log = [] | |
37 | title = [] | |
38 | ||
39 | for item in data[1:]: | |
40 | temp = item.split('</a></li>')[0] | |
41 | ||
42 | lien, titre = temp.split('">') | |
43 | titre = titre.replace(''',"'").replace('"',"'") | |
44 | print(titre) | |
45 | ||
46 | log.append(lien + " " + titre) | |
47 | ||
48 | temp = "<tr><td><a target='_blank' href='http://" + lien + "' >" + titre + "</a></td></tr>" | |
49 | title.append(temp) | |
50 | ||
51 | ||
52 | print(len(title), "topic trouvés" if len(title)>1 else "topic trouvé") | |
53 | ||
54 | if len(title) and input('\nWanna save ? '): | |
55 | ||
56 | title = '\n'.join(title) + '\n' | |
57 | save('fav.html', title) | |
58 | save('historique.log', '\n'.join(log)+ '\n') | |
59 | import ftplib | |
60 | ||
61 | #Use ftplib.FTP_TLS instead if you FTP host requires TLS. | |
62 | session = ftplib.FTP('ftp.website.fr','username','password') | |
63 | session.cwd('www/jvc') | |
64 | file = open('fav.html','rb') # file to send | |
65 | session.storbinary('STOR index.html', file) # send the file | |
66 | file.close() # close file and FTP | |
67 | session.quit() | |
68 | print('done') |