Skip to content

Instantly share code, notes, and snippets.

View khllkcm's full-sized avatar
🎯
Focusing

Khalil Kacem khllkcm

🎯
Focusing
View GitHub Profile
@khllkcm
khllkcm / ForumLibre.py
Last active May 29, 2019 18:24
Scrap the latest Forum Libre url from r/France and serve it.
import requests
import re
import os
import urllib.parse
headers = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"}
response = requests.get("https://reddit.com/r/france/search?sort=new&q=flair%3AForum%2BLibre&restrict_sr=on&t=day", headers=headers)
result = re.search(
r"https://www.reddit.com/r/france/comments/?.{6}/forum_.*?libre.*?20.+?/",
response.text
@khllkcm
khllkcm / tsv_max_len.py
Created October 17, 2016 16:29
Python 3.5 script to calculate the maximum column length of a TSV file.
# -*- coding: utf-8 -*-
file_lines = open('C:\data_p2.txt', 'r').readlines() #list of file lines
fields_lengths = [[] for i in range(6)] #empty 2D list with 6 empty sublists (one for each column)
for line in file_lines:
fields = line.strip().split("\t") #list of the line's fields, strip() removes the tailing "\n".
for i in range(6):
fields_lengths[i].append(len(fields[i])) #each sublist stores the length of each field.
print([max(x) for x in fields_lengths]) #returns the maximum of each sublist; i.e. the maximum length of each column.

Keybase proof

I hereby claim:

  • I am khllkcm on github.
  • I am khllkcm (https://keybase.io/khllkcm) on keybase.
  • I have a public key ASDDZSXanU8JiqWgAwCzhskEl6XcUEBsw1btk7p1tmr5OQo

To claim this, I am signing this object: