You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 KiB
15 KiB
In [2]:
import random import nltk from newsapi import NewsApiClient s = ' '
In [3]:
newsapi = NewsApiClient(api_key='0c00356f65df431ab394d179292075bd') top0 = newsapi.get_everything(q='future', language='en') top1 = newsapi.get_everything(q='futuro', language='it') top2 = newsapi.get_everything(q='futuro', language='es') top3 = newsapi.get_everything(q='future', language='fr')
In [4]:
articles = top0['articles'] a_pos = articles[14] cont_pos= a_pos['description'] cont_pos = cont_pos.split() tag_cont = nltk.pos_tag(cont_pos)
In [5]:
dtot = '' for x in range(20): a = articles[x] d = a['description'] dtot += d dtot = dtot.split() tagged = nltk.pos_tag(dtot)
In [6]:
dat = {} for word, tag in tag_cont: dat[tag] = word keys = dat.keys() output = " + s + ".join([pos for pos in keys])
In [7]:
dataset = {} def my_dict(gr,data,grlista): data = {} for word, tag in tagged: dataset[tag] = word if tag == gr: data[tag] = word grlista.append(word) CClista = [] my_dict('CC','dataCC',CClista) CDlista = [] my_dict('CD','dataCD',CDlista) DTlista = [] my_dict('DT','dataDT',DTlista) EXlista = [] my_dict('EX','dataEX',EXlista) FWlista = [] my_dict('FW','dataFW',FWlista) INlista = [] my_dict('IN','dataIN',INlista) JJlista = [] my_dict('JJ','dataJJ',JJlista) JJRlista = [] my_dict('JJR','dataJJR',JJRlista) JJSlista = [] my_dict('JJS','dataJJS',JJSlista) LSlista = [] my_dict('LS','dataLS',LSlista) MDlista = [] my_dict('MD','dataMD',MDlista) NNlista = [] my_dict('NN','dataNN',NNlista) NNSlista = [] my_dict('NNS','dataNNS',NNSlista) NNPlista = [] my_dict('NNP','dataNNP',NNPlista) PDTlista = [] my_dict('PDT','dataPDT',PDTlista) POSlista = [] my_dict('POS','dataPOS',POSlista) PRPlista = [] my_dict('PRP','dataPRP',PRPlista) RBlista = [] my_dict('RB','dataRB',RBlista) RB = random.choice(RBlista) RBRlista = [] my_dict('RBR','dataRBR',RBRlista) RBSlista = [] my_dict('RBS','dataRBS',RBSlista) RPlista = [] my_dict('RP','dataRP',RPlista) SYMlista = [] my_dict('SYM','dataSYM',SYMlista) TOlista = [] my_dict('TO','dataTO',TOlista) UHlista = [] my_dict('UH','dataUH',UHlista) VBlista = [] my_dict('VB','dataVB',VBlista) VBDlista = [] my_dict('VBD','dataVBD',VBDlista) VBGlista = [] my_dict('VBG','dataVBG',VBGlista) VBNlista = [] my_dict('VBN','dataVBN',VBNlista) VBPlista = [] my_dict('VBP','dataVBP',VBPlista) VBZlista = [] my_dict('VBZ','dataVBZ',VBZlista) WDTlista = [] my_dict('WDT','dataWDT',WDTlista) WPlista = [] my_dict('WP','dataWP',WPlista) WRBlista = [] my_dict('WRB','dataWRB',WRBlista)
In [8]:
CC = random.choice(CClista) CD = random.choice(CDlista) DT = random.choice(DTlista) EX = random.choice(EXlista) #FW = random.choice(FWlista) IN = random.choice(INlista) JJ = random.choice(JJlista) JJR = random.choice(JJRlista) JJS = random.choice(JJSlista) #LS = random.choice(LSlista) MD = random.choice(MDlista) NN = random.choice(NNlista) NNS = random.choice(NNSlista) NNP = random.choice(NNPlista) PDT = random.choice(PDTlista) #POS = random.choice(POSlista) PRP = random.choice(PRPlista) RB = random.choice(RBlista) #RBR = random.choice(RBRlista) #RBS = random.choice(RBSlista) RP = random.choice(RPlista) #SYM = random.choice(SYMlista) TO = random.choice(TOlista) #UH = random.choice(UHlista) VB = random.choice(VBlista) VBD = random.choice(VBDlista) VBG = random.choice(VBGlista) VBN = random.choice(VBNlista) VBP = random.choice(VBPlista) VBZ = random.choice(VBZlista) WDT = random.choice(WDTlista) WP = random.choice(WPlista) WRB = random.choice(WRBlista)
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-8-4ed1abd4d748> in <module> 31 WDT = random.choice(WDTlista) 32 WP = random.choice(WPlista) ---> 33 WRB = random.choice(WRBlista) /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/random.py in choice(self, seq) 288 i = self._randbelow(len(seq)) 289 except ValueError: --> 290 raise IndexError('Cannot choose from an empty sequence') from None 291 return seq[i] 292 IndexError: Cannot choose from an empty sequence
In [130]:
print(output)
DT + s + NNS + s + VBN + s + IN + s + VBG + s + NN + s + WDT + s + VBZ + s + JJ + s + EX + s + VBP + s + CD + s + PRP + s + NNP + s + CC
In [131]:
DT + s + NNS + s + VBN + s + IN + s + VBG + s + NN + s + WDT + s + VBZ + s + JJ + s + EX + s + VBP + s + CD + s + PRP + s + NNP + s + CC
Out[131]:
'the microswimmers confirmed with tearing software that represents Mashable There it’s 2018. them Mashable or'
In [293]:
res = ['The cable who is of technologies are going to be new Read also and','''no world's who tells from rules are figuring to use near Broomstick, ahead or''', 'the mechanism who seeks as owners are figuring to control new Science, again and', 'the presidency, who has in works carry flying to build hard Harry ever and', 'a repository. who PlantsPhysicists about microswimmers deliver... going to act it. Harry likely But', 'the lecture who PlantsPhysicists of issues deliver... flailing to be different Fluora, up and', 'a cable who has in poets think averting to be electric CEO half-jokingly and', 'the male who fits of submissions are helping to use fellow Texas half-jokingly and', 'the toy who is of he’d it’s helping to get electric Black much and', 'a unease who represents orgasm. sensors think averting to act free PS5 also and', 'the more...Jennifer who fits of reveals believe offering to streaming. major Fluora, actually and', 'the sanitizer who represents in reorganizations are figuring to perform adjustable Tech, likely or']
In [294]:
res
Out[294]:
['The cable who is of technologies are going to be new Read also and', "no world's who tells from rules are figuring to use near Broomstick, ahead or", 'the mechanism who seeks as owners are figuring to control new Science, again and', 'the presidency, who has in works carry flying to build hard Harry ever and', 'a repository. who PlantsPhysicists about microswimmers deliver... going to act it. Harry likely But', 'the lecture who PlantsPhysicists of issues deliver... flailing to be different Fluora, up and', 'a cable who has in poets think averting to be electric CEO half-jokingly and', 'the male who fits of submissions are helping to use fellow Texas half-jokingly and', 'the toy who is of he’d it’s helping to get electric Black much and', 'a unease who represents orgasm. sensors think averting to act free PS5 also and', 'the more...Jennifer who fits of reveals believe offering to streaming. major Fluora, actually and', 'the sanitizer who represents in reorganizations are figuring to perform adjustable Tech, likely or']
In [447]:
export = 'news.txt' with open(export, 'w') as export: print('<head>harset=utf-8</head>') print('<h1>News from the future</h1>', file=export) print('<br><br><br><br><br><br><br><br><br><br><br><br>', file = export) for x in range(len(res)): print(f'''{res[x].lower().capitalize()}. ''',file=export) print('<br><br><br><br><br><br><br><br><br><br><br><br><br><br>', file = export)
<head>harset=utf-8</head>
In [448]:
!pandoc news.txt | weasyprint -s css.css - newsfromthefuture.pdf
Fontconfig warning: ignoring UTF-8: not a valid region tag
In [ ]:
In [411]:
a_pos = open('language.txt').read() cont_pos = a_pos.split() tag_cont = nltk.pos_tag(cont_pos)
In [321]:
dat = {} for word, tag in tag_cont: dat[tag] = word keys = dat.keys() output = " + s + ".join([pos for pos in keys])
In [330]:
Out[330]:
'Led and broom believe likely American of can test has called sensors the which There smallest 300 selected They who They to'
In [ ]: