What is preventing some of the content from an Invoke-WebRequest showing? - powershell

I am trying to get some acsii art characters directly from a webpage. You can navigate to the page using the following URL.
http://patorjk.com/software/taag/#p=display&f=Acrobatic&t=A
If you go to that page you will see a rendering of the character A using the Acrobatic font.
o
<|>
/ \
o/ \o
<|__ __|>
/ \
o/ \o
/v v\
/> <\
Using the following code nets me most of the page.
$fontUrlTemplate = "http://patorjk.com/software/taag/#p=display&f={0}&t={1}"
$fontName = [uri]::EscapeUriString("Acrobatic")
$character = "A"
$fontUrl = $fontUrlTemplate -f $fontName, $character
$webResult = Invoke-WebRequest $fontUrl
$webResult.Content
However when I inspect the Content the actual result I am looking for is missing.
...
<div id="maincontent" >
<div id="outputFigDisplay" ></div>
</div>
...
There should be something like this in there
<pre id="taag_output_text" style="float:left;" class="fig" contenteditable="true">...</pre>
I am sure there is a server side reason for this but I would like to better understand and, if possible, mitigate it. I have tried mucking around with -ContentType and -UserAgent but it didn't change anything

Related

SharePoint Office365 Powershell Webpart AllItems.aspx

Using powershell, add webpart (image) to the list view page, e.g. AllItems.aspx.
This code is ok when I adding webpart to sitepage but what/how can do the same things in list
$mySite = Get-PnPClientSidePage -Identity "TestWP.aspx"
$jsonProp = '{
"imageSourceType":0,
"imageSource":"https://MMMMMM.sharepoint.com/sites/pwa/SiteAssets/img01.jpg",
"captionText":" ",
"altText":" ",
"linkUrl":"",
"overlayText":"",
"fileName":"",
"siteId":"",
"webId":"",
"listId":"",
"uniqueId":"",
"imgWidth":"100%",
"imgHeight":"100%"
}'
Add-PnPClientSideWebPart -Page $mySite -Section 1 -Column 1 -Order 1 -DefaultWebPartType Image -WebPartProperties $jsonProp
E.g. in the AllItems.aspx view -> edit page -> Insert -> Image
or Add a Web Part.
example in the link.
img01
img02
coffee, a little break and I got it
first manually adding a web part to the test page then download webpart in xml format
# get xml
$imgWebPart = Get-PnPWebPartXml -ServerRelativePageUrl "/sites/pwa/Lists/TestList03/AllItems.aspx" -Identity "Image Viewer"
Add-PnPWebPartToWebPartPage -ServerRelativePageUrl "/sites/pwa/Lists/TestList03/aa.aspx" -Xml $imgWebPart -ZoneId Main -ZoneIndex 0
sorry for the confusion.

Invoke-RestMethod in Powershell only returning inner entry elements and not feed

I am calling Powershell's Invoke-RestMethod on a feed with the following structure
<feed>
<id>feed id</id>
<author><name>John Smith</name></author>
<title>Feed title</title>
<updated>2017-03-17T12:57:28.898Z</updated>
<link href="url A" rel="value A"/>
<link href="url B" rel="value B"/>
... other elements ...
<entry>
<id>entry id</id>
<author><name>John Smith</name></author>
<title>Entry title</title>
<updated>2017-03-17T12:57:28.898Z</updated>
<link href="url C" rel="value C"/>
<link href="url D" rel="value D"/>
... other elements ...
</entry>
</feed>
I am using the following function
$xml = Invoke-RestMethod -Method Get -Uri $Url -ContentType "application/atom+xml" -Credential $credentials
I get a successful response, but it only includes the <entry> element and not the <feed> element, and I need the values of the "url A" and "url B" links which are therefore not returned.
Normally I would say what I have tried at this point, but since I've found nothing on the internet, these are the only things I've tried.
Changing the request content type to "text/xml" - no change in the result.
Calling $xml.ParentNode and $xml.OwnerDocument in attempt to get the <feed> element, but it was not available.
How can I get the <feed> level elements?
My Powershell version is 5.1.14393.953
Thanks
Invoke-RestMethod only returns the entries in a rss or atom-feed, as stated on MSDN:
Windows PowerShell formats the response based to the data type. For an
RSS or ATOM feed, Windows PowerShell returns the Item or Entry XML
nodes. For JavaScript Object Notation (JSON) or XML, Windows
PowerShell converts (or deserializes) the content into objects.
You can use Invoke-WebRequest to read the original xml and access the feed-element. Ex.
$xml = [xml](Invoke-WebRequest -Uri $url -Credential $credentials)
Sample output:
PS> $xml.feed
xmlns : http://www.w3.org/2005/Atom
title : VG ATOM Feed
link : {link, link}
id : http://www.vg.no/rss/feed/forsiden/?format=atom
updated : 2017-03-19T18:36:56+01:00
entry : {entry, entry, entry, entry...}

powershell invoke-webrequest with codepage win 1251

I need to get data from a page that has the win-1251 codepage.
$SiteAdress = "http://www.gisinfo.ru/download/download.htm"
$HttpContent = Invoke-WebRequest -URI $SiteAdress
echo $HttpContent
And it shows me:
> StatusCode : 200 StatusDescription : OK Content :
> <!DOCTYPE html>
> <html><!-- #BeginTemplate "/Templates/panorama.dwt" --><!-- DW6 -->
> <head>
> <!-- #BeginEditable "doctitle" -->
> <title>ÃÈÑ ÏÀÍÎÐÀÌÀ - Ñêà÷àòü ïðîãðàììû</title>
> <meta name="keywords" con... RawContent : HTTP/1.1 200 OK
> Transfer-Encoding: chunked
> Connection: keep-alive
> Keep-Alive: timeout=20
> Content-Type: text/html
> Date: Fri, 16 Oct 2015 12:40:45 GMT
> Server: nginx/1.5.7
> X-Powered-By: PHP/5.2.17...
Title is Cyrillic. I have tried the variant below, but the result is the same.
$HttpContent = Invoke-WebRequest -URI $SiteAdress -ContentType "text/html; charset=windows-1251"
The -ContentType parameter to Invoke-WebRequest sets the content type for the request, not the response. Since you don't sent any content with your request it's quite irrelevant here.
I didn't find an easy way of enforcing a particular encoding for the response. Since the encoding is only specified within the HTML, and not the response header, there's little you can do here, I fear, as Invoke-WebRequest isn't smart enough to figure that out on its own.
You can, however, convert the text you read:
filter Convert-Encoding {
$1251 = [System.Text.Encoding]::GetEncoding(1251)
$1251.GetString([System.Text.Encoding]::Default.GetBytes($_))
}
$HttpContent.Content | Convert-Encoding
will then yield the proper Cyrillic text.
<!DOCTYPE html>
<html><!-- #BeginTemplate "/Templates/panorama.dwt" --><!-- DW6 -->
<head>
<!-- #BeginEditable "doctitle" -->
<title>ГИС ПАНОРАМА - Скачать программы</title>
<meta name="keywords" content="ГИС, карта, геодезия, картография, фотограмметрия, топография, электронная карта, классификатор, трехмерное моделирование, модель местности, карта Москвы, Ногинск, кадастр, межевое дело, Гаусс, эллипсоид Красовского, 1942, оротофотоснимок, WGS, растр, план, схема, бланковка, фотодокумент, земля, право, документация, map, sit, mtw, mtr, rsw, rsc, s57, s52, gis, 2003, 2004, Tool, Kit">
<meta name="description" content="Новые версии ГИС Карта 2000, GIS ToolKit , СУРЗ Земля и Право, документации, библиотек и примеров электронных карт">
<!-- #EndEditable -->
In any case, you need to know the exact encoding beforehand, regardless of how you solve it. You could try finding it in the HTML source, though:
[Regex]::Matches($HttpContent.Content, 'text/html;\s*charset=(?<encoding>[1-9a-z-]+)')
[System.Text.Encoding]::GetEncoding can cope with a string like windows-1251, at least.
My working variant:
$client = New-Object System.Net.WebClient
$url = "http://www.gisinfo.ru/download/download.htm"
$results = [System.Text.Encoding]::GetEncoding('windows-1251').GetString([Byte[]]$client.DownloadData($url))
Thanks Joey for help

Pulling Data from Google spreadsheet

I am having difficulty pulling data from Google spreadsheet
I have added following gem files
gem 'roo'
gem 'google_drive'
gem 'google-spreadsheet-ruby'
My jobs file is
require 'roo'
require 'rubygems'
def fetch_spreadsheet_data()
google_user = "MY EMAIL ADDRESS"
google_password = "MY PASSWORD"
workbook = Roo::Google.new("https://docs.google.com/spreadsheet/ccc?key=1hdwnrDsuJId1FLE0yWICYP1HGqYNu2NHH2IcoPyAzOQ#gid=0",user: google_user, password: google_password)
send_event('catchup_data', {current: s.cell('B',2) })
send_event('Bounced_back', {current: s.cell('B',3) )
end
SCHEDULER.every '5m' do
fetch_spreadsheet_data()
end
My dashboard.erb file has following html
<li data-row="2" data-col="3" data-sizex="1" data-sizey="1">
<div data-id="bounce_back" data-view="Number" data-title="Triage - Work in Progress" style="background-color:#5AC352;"></div>
</li>
<li data-row="2" data-col="4" data-sizex="1" data-sizey="1">
<div data-id="catchup_data" data-view="Number" data-title="Squad catchup sessions last month" style="background-color:#DBA901;"></div>
</li>
Not sure what am I missing that the data is not coming through. Can anyone please help me?
There are a few things wrong that I can see:
You're sending 'Bounced_back' but binding to the id of 'bounce_back'
You are trying to get the cell data from 's' but 's' is undefined
Looking at the Roo docs, I believe you have copied 's' from there. Just above that, they use sheet instead so I believe you have to grab the sheet from the workbook before using it.
I googled a bit and found this: http://etzelstorfer.com/en/dashing-graph-from-google-spreadsheet/
In summary, this should work for you:
def fetch_spreadsheet_data()
google_user = "MY EMAIL ADDRESS"
google_password = "MY PASSWORD"
workbook = Roo::Google.new("https://docs.google.com/spreadsheet/ccc?key=1hdwnrDsuJId1FLE0yWICYP1HGqYNu2NHH2IcoPyAzOQ#gid=0",user: google_user, password: google_password)
s = workbook.sheets[0] # assuming first sheet in workbook
send_event('catchup_data', {current: s.cell('B',2) })
send_event('bounce_back', {current: s.cell('B',3) )
end
SCHEDULER.every '5m' do
fetch_spreadsheet_data()
end

Change epydoc's favicon - how to?

Everything is in the question :
How would I do to change epydoc's generated html pages favicon ?
Note : I saw how to customize the css content, but nothing about customizing output html files...
Many thanks.
Ok, so after a littel brainstorming (with myself), I found a way :
Since we can inject some html using --navlink option to epydoc (initially designed to customize project's link in the navigation bar), I used a javascript trick to add the following dynamically in the tag of the document.
Here is the javascript code :
var link = parent.document.createElement('link');
link.id = 'dynamic-favicon';
link.type = 'image/png';
link.rel = 'shortcut icon';
link.href = '../logo-fav.png'; parent.document.head.appendChild(link);
parent.document.head = parent.document.head ||
parent.document.getElementsByTagName('head')[0];
And here is the full epydoc command line :
epydoc -v --name "My Project" -o ./html \
--css epydoc.css --url http://www.my-project.org --inheritance listed \
--graph all --no-private --docformat epytext \
--navlink "<img src=\"../logo.png\" style=\"margin:10px;\" />
<script>
var link = parent.document.createElement('link');
link.id = 'dynamic-favicon';
link.type = 'image/png';
link.rel = 'shortcut icon';
link.href = '../logo-fav.png';
parent.document.head.appendChild(link);
parent.document.head = parent.document.head || parent.document.getElementsByTagName('head')[0];
</script>
" \
my_py_module
This can be used to customize the whole documentation, but is still hacky. Still strange that their is no way to use some templates in such a mature tool like epydoc...