Modul:Sportklubb WD

Från Wikipedia
Hoppa till navigering Hoppa till sök

Dokumentationen för denna modul kan skapas på Modul:Sportklubb WD/dok

p = {}
--local wd = require( 'Modul:Referenshantering' )

p.iRefcounter=0

--Labels & Headers
txtFoundedDate='Grundad'
txtSeat='Säte'
txtHomeVenue='Hemmaplan'
txtWebsite='Webbplats'

txtClubTeamResultHeader='Resultat'
txtClubCoachesHeader='Tränare'

txtCompetitionHeader="Tävling"
txtNameHeader="Namn"
txtSeasonHeader="År"

txtPositionHeader='Plats'

--For templates
txtInfoboxTemplate='Faktamall'
txtFlagIconTemplate='Flaggbild'
txtSourceNeededWDTemplate='Källa behövs WD'

txtHeader='rubrik'
txtLabel='etikett'
txtContent='innehåll'

txtTeamHeaderStyle='bgcolor="#eaecf0" align="center"'
txtLanguageCode='sv' 

txtEditComment='Redigera uppgifter i faktarutan'

--For Layout
txtStyleMain='background:orange;'
txtStyleLevel2='background:gold'
txtWidth_px='260px'


function txtEditPen(iEntity,iProperty)
	local edit_message = mw.message.new('vector-view-edit'):plain()

	return '<sup class="noprint Inline-Template">&nbsp;[[File:Arbcom_ru_editing.svg|' 
	                   	.. edit_message .. '|8px|baseline|class=noviewer|link=https://www.wikidata.org/wiki/' 
	                   	.. iEntity .. '#' .. iProperty .. ']]</sup>'
end

function getProperty(value,txtPropertyId)
	if value['qualifiers'] and  value['qualifiers'][txtPropertyId] then
			txtValue=emptyifNil(mw.wikibase.renderSnak(value['qualifiers'][txtPropertyId][1]))
		else
			txtValue=nil
		end
	return txtValue
end

function getOneValue(entity,txtProperty)
	statements=entity:getBestStatements( txtProperty)
	if next(statements)==nil then
		return nil
		else
		return getLabelByEntity(read(statements[1],'id'))
		end
	end

function getOneEntityId(entity,txtProperty)
	statements=entity:getBestStatements( txtProperty)
	if next(statements)==nil then
		return nil
		else
		return read(statements[1],'id')
		end
	end

function getPropertyId(value,txtPropertyId)
	if value['qualifiers'] then
		if value['qualifiers'][txtPropertyId] then
			txtSnaktype=value['qualifiers'][txtPropertyId][1].snaktype
			if (txtSnaktype=="value") then
				txtValue=readQualifier(value['qualifiers'][txtPropertyId][1],'id')
				else
				txtValue="Not Implemented"
				end
			else
			txtValue=nil
		end
		else
			txtValue=nil
end			
	return txtValue
end

function emptyifNil(data)
	if (data) then
		return data
		else
		return ''
	end
end

function getLabelByEntity( id )
	return mw.wikibase.getEntity( id ):getLabel( txtLanguageCode )
end


--Read a value of a property
function read(data,type)
	return readQualifier(data['mainsnak'],type)
end

--Read a value of a qualifier
function readQualifier(data,type)
	return data['datavalue']['value'][type]
end



p.club = function(frame)
	entityid=mw.wikibase.getEntityIdForCurrentPage()
	entity=mw.wikibase.getEntity(entityid) 	
	wdTitle=getLabelByEntity( entityid )
    myArgs={titel=wdTitle}
	img=entity:getBestStatements( 'P18' )
	if frame.args['width_px']~=nil then
		txtWidth_px=frame.args.width_px
		end
	if next(img) then
		wdImage = img[1]['mainsnak']['datavalue']['value']
	    myArgs['bild']='[[File:' .. wdImage .. '|' .. txtWidth_px .. ']]'  .. txtEditPen(entityid,'P18')
	    else
		img=entity:getBestStatements( 'P154' )
		if next(img) then
			wdImage = img[1]['mainsnak']['datavalue']['value']
		    myArgs['bild']='[[Bild:' .. wdImage .. '|' .. txtWidth_px .. ']]'  .. txtEditPen(entityid,'P154')
		    end
		end
    myArgs['rubrikstil'] = txtStyleMain
    iCounter=0
	entityFoundedDate=entity:getBestStatements( 'P571' )
	if next(entityFoundedDate) then
    	iCounter=iCounter+1
	    myArgs[txtLabel .. iCounter]=txtFoundedDate
    	myArgs[txtContent  .. iCounter]=entity:formatPropertyValues( 'P571' )['value'] .. txtUnpackReference(frame,tblProcessAllRefsForItemWD(frame,entityFoundedDate[1].references,entityid,'P569'))
	end
	entityPlace=entity:getBestStatements( 'P159' )
	wdPlace=''
	iPlaces=0
    for key, value in pairs( entityPlace ) do
    	iPlaces=iPlaces+1
    	idPlace=value.mainsnak.datavalue.value.id
	  	entityPlace2=mw.wikibase.getEntity(idPlace) 	
		wdCountry = getOneValue(entityPlace2,'P17')
		if (iPlaces>1) then
			wdPlace = wdPlace .. ' och '
			end
		wdPlace = wdPlace .. txtWikilink(idPlace)  .. ', ' .. frame:expandTemplate{ title = 'Flaggbild' , args={wdCountry}} .. ' [[' .. wdCountry .. ']]' .. txtUnpackReference(frame,tblProcessAllRefsForItemWD(frame,value.references,entityid,'P159')) .. txtEditPen(entityid,value.id)
    	end
	if not (wdPlace=='') then
    	iCounter=iCounter+1
	    myArgs[txtLabel .. iCounter]=txtSeat
    	myArgs[txtContent  .. iCounter]=wdPlace
		end
	entityHomeVenue=entity:getAllStatements( 'P115' )
	wdHomeVenue=''
    for key, value in pairs( entityHomeVenue ) do
	    idHomeVenue=value.mainsnak.datavalue.value.id
		wdHomeVenue = wdHomeVenue .. txtWikilink(idHomeVenue)
		entityVenue=mw.wikibase.getEntity(idHomeVenue)
		wdCapacity=entityVenue:formatPropertyValues( 'P1083' )['value']
		if not (wdCapacity=='') then
			wdHomeVenue=wdHomeVenue .. ' (' .. wdCapacity .. ' platser)'
			end
		wdHomeVenue=wdHomeVenue .. txtUnpackReference(frame,tblProcessAllRefsForItemWD(frame,value.references,entityid,'P115')) .. txtEditPen(entityid,value.id)
	    end
	if not (wdHomeVenue=='') then
		iCounter=iCounter+1
	    myArgs[txtLabel .. iCounter]=txtHomeVenue
		myArgs[txtContent  .. iCounter]=wdHomeVenue
		end
	entityWebsite=entity:getBestStatements( 'P856' )
    if next(entityWebsite) then
    	iCounter=iCounter+1
		wdWebsite = entityWebsite[1].mainsnak.datavalue.value
		if (#wdWebsite>30) then
			wdWebsite='[' .. wdWebsite .. ' Officiell webbplats]'
			end
	    myArgs[txtLabel .. iCounter]=txtWebsite
    	myArgs[txtContent  .. iCounter]=wdWebsite .. txtEditPen(entityid,'P856')
    	end
	iCounter=iCounter+1
	bHasResults,txtTeamresults=teamresults(frame,entity,entityid)
	if (bHasResults) then
	    myArgs[txtHeader .. iCounter]=txtClubTeamResultHeader;
		iCounter=iCounter+1
	    myArgs[txtContent .. iCounter]=txtTeamresults
		iCounter=iCounter+1
		end
	bHasCoaches,txtCoaches=teamcoaches(frame,entity,entityid)
	if (bHasCoaches) then
	    myArgs[txtHeader .. iCounter]=txtClubCoachesHeader;
--	    myArgs['rubrik' .. iCounter .. 'stil']=txtStyleLevel2;
		iCounter=iCounter+1
	    myArgs[txtContent .. iCounter]=txtCoaches
		iCounter=iCounter+1
		end
	myArgs['under']='[https://www.wikidata.org/wiki/' .. entityid .. ' '.. txtEditComment .. ']'
	tmp = frame:expandTemplate{ title = txtInfoboxTemplate , args =myArgs}
	return tmp
	end

function txtWikilink(id)
	txtSitelink=mw.wikibase.getSitelink(id)
	if (txtSitelink) then
		return '[[' .. txtSitelink .. '|' .. getLabelByEntity(id) .. ']]'
		else
		return '[[' .. getLabelByEntity(id) .. ']]'
		end
end

function teamname(idTeam,year)
	local entityTeam=mw.wikibase.getEntity(idTeam) 	
	local claims = entityTeam:getBestStatements('P1448' ) -- If the club have had many names, loop through to find the one that was used when the player played at the club
	local txt
	if (next(claims)) then
		if (year) then
			txt=year else
			txt=''
			end
	    for key, value in pairs( claims ) do
			yearfrom,yearto =  years(value) 
	    	txt=txt.. '(' .. yearfrom .. ':' .. yearto .. ')'
	    	if (year >= yearfrom and year <= yearto) then
	    		txtName=read(value,'text')
    			end
    		end
		return '[[' ..  getLabelByEntity( idTeam ) .. '|' .. txtName .. ']]'
		else
		return '[[' ..  getLabelByEntity( idTeam ) .. ']]'
		end
end

function teamresults (frame,entity,iTeam)
	local out = {}
	local all={}
	local d={}
	local t={}
	local txt=''
    local claimsCompetition = entity:getBestStatements( 'P1344' )
    for key, value in pairs( claimsCompetition ) do
		local tmp={}
		local id = read(value,'id')
		tmp.iSeason=id
--		entityLeagueYear=mw.wikibase.getEntity(id) 	
		tmp=sasongsinfo_local(frame,tmp,value,entity)
		--tmp.iPosition=getProperty(value,'P1352')
		table.insert(all,tmp)
    end 
    table.sort(all, function(a, b) return a.txtLeague < b.txtLeague or (a.txtLeague==b.txtLeague and a.txtDate > b.txtDate) end)
	txt=txt .. '<table style="class: biography vcard" width="100%"><tr><th width="30px">' .. txtPositionHeader .. '</th><th>' .. txtSeasonHeader .. '</th></tr>'
	txtCompetitionOld=''
	for i = 1,#all do
		if (all[i].txtLeague~=txtCompetitionOld) then
			txt=txt .. '<tr ' .. txtTeamHeaderStyle .. '><td colspan="2"><b>' .. firstToUpper(all[i].txtLeague) .. '</b></td></tr>'
			txtCompetitionOld=all[i].txtLeague
			end
		txtSeasonLink=mw.wikibase.getSitelink(all[i].iSeason )
		if not(txtSeasonLink) then
			txtSeasonLink= getLabelByEntity(all[i].iSeason) 
			end				
		if (all[i].iStatus==3) then
			txtSeasonShow='aaa' .. all[i].txtSeason
			else
			txtSeasonShow=firstToUpper(all[i].txtSeason)
			end
		txt=txt ..'<tr>' .. txtPosition(all[i].iPosition) .. '<td>[[' .. txtSeasonLink .. '|' .. txtSeasonShow  .. ']] '.. txtUnpackReference(frame,all[i].hasref,all[i].ref) .. all[i].edit  .. '</td></tr>'
    end
	txt=txt .. '</table>'
	return #all>0,txt
end

--Fill table with information about the player's time at a club
function tblTeamInfo(frame,value,entityid,txtProperty)
	local tmp={}
	tmp.yearfrom,tmp.yearto = years(value) 
	tmp.txtCompetition=txtWikilink(read(value,'id'))
	tmp.hasref,tmp.ref=tblProcessAllRefsForItemWD(frame,value['references'],entityid,txtProperty)
	tmp.edit=txtEditPen(entityid,value.id)
	return tmp
end

function teamcoaches (frame,entity,iTeam)
	local out = {}
	local all={}
	local txt=''
    local claimsCompetition = entity:getBestStatements( 'P286' )
    for key, value in pairs( claimsCompetition ) do
		local tmp={}
		local id = read(value,'id')
		entityPerson=mw.wikibase.getEntity(id)
		local tmp=tblTeamInfo(frame,value,iTeam,'P286')
		table.insert(all,tmp)
    end 
    table.sort(all, function(a, b) return a.startyear > b.startyear end)
	txt=txt .. '<table style="class: biography vcard" width="100%"><tr><th>' .. txtNameHeader .. '</th><th>' .. txtSeasonHeader .. '</th></tr>'
	txtCompetitionOld=''
	for i = 1,#all do
		txt=txt .. '<tr>'
		txt=txt .. '<td>' .. all[i].txtCompetition .. '</td>'
		txt=txt .. '<td>' .. txtYears(all[i].startyear,all[i].endyear)  .. txtUnpackReference(frame,all[i].hasref,all[i].ref) .. all[i].edit .. '</td></tr>'
    end
	txt=txt .. '</table>'
	return #all>0,txt
end

function txtPosition(iPosition)
	local bMedal=0
	if not (iPosition==nil) then
		if (iPosition=="1") then
			txtPosColour='gold'
			bMedal=1
			end
		if (iPosition=="2") then
			txtPosColour='silver'
			bMedal=1
			end
		if (iPosition=="3") then
			txtPosColour='bronze'
			bMedal=1
			end
		if (bMedal==1) then
			return '<td align="center" bgcolor="' .. txtPosColour .. '">' .. iPosition  .. '</td>'
			else
			return '<td>' .. iPosition  .. '</td>'
			end
		else
		return '<td></td>'
		end
end

function txtYears(startyear,endyear)
if (startyear=='' or startyear==nil) then
	if (endyear=='' or endyear==nil) then
		return '–'
		else
		return '–' .. endyear
		end
	else
	if (endyear==startyear) then
		return startyear
		else
		return startyear .. '–' .. endyear
		end
	end
end

function years(value)
	if value['qualifiers'] then
		if value['qualifiers']['P580'] then
			startyear=emptyifNil(mw.wikibase.renderSnak(value['qualifiers']['P580'][1]))
			else
			startyear=''
			end
		if value['qualifiers']['P582'] then
			endyear=emptyifNil(mw.wikibase.renderSnak(value['qualifiers']['P582'][1]))
			else
			endyear=''
			end
		return startyear,endyear
		else
			return '',''
		end
end

function processDates(entity)
	txtDate=''
	local p580=entity:getAllStatements( 'P580' )
	local isnext=next(p580)
	if isnext then
		txtDate=read(p580[1],'time')
		txtYearFrom=string.sub(txtDate,2,5)
		p582=entity:getAllStatements( 'P582' )
		if (next(p582)) then
			txtYearTo=string.sub(read(p582[1],'time'),2,5)
			else
			txtYearTo=''
			end
		txtSeason=txtYears(txtYearFrom,txtYearTo)
		end
	return isnext,txtDate,txtYearFrom,txtSeason
end


function sasongsinfo_local(frame,tbl,value,entity)
	tbl.iStatus=1														-- Everything ok	
	local entityCompetition=mw.wikibase.getEntity(tbl.iSeason) 
    local claimsLiga = entityCompetition:getAllStatements( 'P3450' )
    tbl.txtDate=''
    if (claimsLiga[1]) then											-- Has a link to leauge (from the individual season) 
	    local formatedLeague= entityCompetition:formatPropertyValues( 'P3450' )
		txtThisLeague=firstToUpper(formatedLeague['value'])
	    local idSerie=read(claimsLiga[1],'id')
		local txtWikipediaLeagueName=mw.wikibase.getEntity(idSerie):getSitelink( txtLanguageCode .. 'wiki' )
		if (txtWikipediaLeagueName) then
			tbl.txtLeague = '[[' .. txtWikipediaLeagueName .. '|' .. txtThisLeague .. ']]'
			else
			tbl.txtLeague = '[[' .. txtThisLeague .. ']]'
			end
		else
		tbl.txtLeague='Tävlingstyp ej satt'
		tbl.iStatus=2
	    end
	bFounddates,tbl.txtDate,tbl.txtYearFrom,tbl.txtSeason=processDates(entityCompetition)
	if not bFounddates then
		--If no start year check for era	
		p2348=entityCompetition:getAllStatements( 'P2348' ) -- Om tidsperiod
		if (next(p2348)) then
			bFounddates,tbl.txtDate,tbl.txtYearFrom,tbl.txtSeason=processDates(mw.wikibase.getEntity(read(p2348[1],'id')) )
		end
	end
	if not bFounddates then
		p585=entityCompetition:getAllStatements( 'P585' ) -- Om tidsperiod
		if (next(p585)) then
			tbl.txtDate=read(p585[1],'time')
			tbl.txtYearFrom=string.sub(tbl.txtDate,2,5)
			tbl.txtSeason=tbl.txtYearFrom
			else
			-- If neither startyear nor era, do not try do display more detailed information, just display information about the season of the league	
--				tbl.txtSeason=entity:getLabel( txtLanguageCode )
			tbl.txtSeason=tprint(entityCompetition)
			tbl.iStatus=3
			end
		end
	claimTeams=entityCompetition:getBestStatements( 'P1923' )
	txtRet=''
    for key, value in pairs(claimTeams ) do
		iTeamLoop=read(value,'id')
		if (iTeamLoop==tbl.iTeam) then
			if (value.qualifiers) then
				txtRet=txtRet .. string.sub(readQualifier(value.qualifiers.P1352[1],'amount'),2,-1)
				end
			break
		    end
    	end
    tbl.iPosition=txtRet
	iPositionDirect=getProperty(value,'P1352')
	if not (iPositionDirect=='') then
		tbl.iPosition=iPositionDirect
		end
	tbl.txtCountry = getOneValue(entity,'P17')
	entityid=entity:getId()
	tbl.hasref,tbl.ref=tblProcessAllRefsForItemWD(frame,value['references'],entityid,'P1344')
	tbl.edit=txtEditPen(entityid,value.id)
	return tbl
end

-- the "qualifiers" and "snaks" field have a respective "qualifiers-order" and "snaks-order" field
-- use these as the second parameter and this function instead of the built-in "pairs" function
-- to iterate over all qualifiers and snaks in the intended order.
local function orderedpairs(array, order)
	if not order then return pairs(array) end

	-- return iterator function
	local i = 0
	return function()
		i = i + 1
		if order[i] then
			return order[i], array[order[i]]
		end
	end
end

local function getSnakValue(snak, parameter)
	if snak.snaktype == "value" then
		-- call the respective snak parser
		if snak.datavalue.type == "string" then return snak.datavalue.value
		elseif snak.datavalue.type == "globecoordinate" then return printDatavalueCoordinate(snak.datavalue.value, parameter)
		elseif snak.datavalue.type == "quantity" then return printDatavalueQuantity(snak.datavalue.value, parameter)
		elseif snak.datavalue.type == "time" then return printDatavalueTime(snak.datavalue.value, parameter)
		elseif snak.datavalue.type == "wikibase-entityid" then return printDatavalueEntity(snak.datavalue.value, parameter)
		elseif snak.datavalue.type == "monolingualtext" then return printDatavalueMonolingualText(snak.datavalue.value, parameter)
		end
	end
	return mw.wikibase.renderSnak(snak)
end

function __genOrderedIndex( t )
    local orderedIndex = {}
    for key in pairs(t) do
        table.insert( orderedIndex, key )
    end
    table.sort( orderedIndex )
    return orderedIndex
end

function orderedNext(t, state)
    -- Equivalent of the next function, but returns the keys in the alphabetic
    -- order. We use a temporary ordered key table that is stored in the
    -- table being iterated.

    local key = nil
    --print("orderedNext: state = "..tostring(state) )
    if state == nil then
        -- the first time, generate the index
        t.__orderedIndex = __genOrderedIndex( t )
        key = t.__orderedIndex[1]
    else
        -- fetch the next value
        for i = 1,table.getn(t.__orderedIndex) do
            if t.__orderedIndex[i] == state then
                key = t.__orderedIndex[i+1]
            end
        end
    end

    if key then
        return key, t[key]
    end

    -- no more value to return, cleanup
    t.__orderedIndex = nil
    return
end

function orderedPairs(t)
    -- Equivalent of the pairs() function on tables. Allows to iterate
    -- in order
    return orderedNext, t, nil
end

-- from: https://stackoverflow.com/questions/2421695/first-character-uppercase-lua
function firstToUpper(str)
	if (str) then
	    return (str:gsub("^%l", string.upper))
	    else
	    return ''
	    end
end

--Text strings for localisation (sources)
txtCiteweb='webbref'   -- Name for the template used for citations of on-line sources
txtPublisher='utgivare'
txtDateTemplate='datum'
txtUrl='url'
txtLanguage='språk'
txtTitle='titel'
txtAuthor='författare'

local d={}
local t={}

function tblProcessIndividualReference(thisref)
	local refparts=thisref.snaks
	table.sort(refparts)

	txt='{{' .. txtCiteweb
	iHadTitle=0
	iFound=1
	isok=1
	txtUrlLocal=''
	for key, value in orderedPairs( refparts) do
		if (key=='P123') then 
			iPublisher=readQualifier(value[1],'id')
			txt=txt .. '|' .. txtPublisher .. '=[[' ..  getLabelByEntity( iPublisher ) .. ']]'
			end
		if (key=='P143') then 
			txt="Från en annan språkversion"
			isok=0
			end
		if (key=='P248') then 
			txtSource=readQualifier(value[1],'id')
			iFound=0
			if (txtSource=="Q95606922") then
				txt='{{Olympedia'
				iFound=1
				iHadTitle=1
				break
			end
			if (txtSource=="Q106762278") then
				txt='{{CEV player'
				iFound=1
				iHadTitle=1
				break
			end
			if (iFound==0) then
				txt='{{Q|'..txtSource..'}}'
			end
			end
		if (key=='P577') then 
			txt = txt .. '|' .. txtDateTemplate .. '='.. string.sub(readQualifier(value[1],'time'),2,11) 
			end
		if (key=='P813') then 
			txt = txt .. '|hämtdatum='.. string.sub(readQualifier(value[1],'time'),2,11) 
			end
		if (key=='P854') then 
			txtUrlLocal=value[1].datavalue.value
			txt = txt .. '|' .. txtUrl .. '='.. txtUrlLocal
			end
		if (key=='P1476') then 
			txt = txt .. '|' .. txtLanguage .. '='.. readQualifier(value[1],'language')
			txt = txt .. '|' .. txtTitle .. '='.. string.gsub(readQualifier(value[1],'text'),"|"," - ")
			iHadTitle=1
		end
		if (key=='P2093') then
			txt = txt .. '|' .. txtAuthor .. '=' .. value[1].datavalue.value
		end
		if (key=='P4656') then 
			txt="Från språkversion"
			isok=0
			end
		if (key=='P8286') then 
			txt = txt .. '|id='.. value[1].datavalue.value
			end

		end
	txt=txt .. '}}'
	if (iFound==1 and iHadTitle==0) then
		txt=txtUrlLocal
		end
	return isok,txt 
end

function tblProcessAllRefsForItemWD(frame,tblReferences,idEntity,idProperty)
local tmpResult={}
iHasSource=0;
if (tblReferences) then
	for keyRef, valueRef in pairs(tblReferences) do
		local isok,refparts=tblProcessIndividualReference(valueRef)
		if (isok==1) then
			iHasSource=1;
			p.iRefcounter=p.iRefcounter+1
			bNotInTable=true
			iIdInTable=k
		    if d[refparts]~=nil then
		    	bNotInTable=false
		    	result={name='wikidatabox'..d[refparts], content=refparts}
			    else
		    	result={name='wikidatabox'..p.iRefcounter, content=refparts}
				d[refparts]=p.iRefcounter
			    end
		    table.insert(tmpResult,result)
		    end
		end
		if (iHasSource==0) then
			tmpResult=frame:expandTemplate{ title = txtSourceNeededWDTemplate,args = {objektid=idEntity,egenskapsid=idProperty}}
			end
		else
		tmpResult=frame:expandTemplate{ title = txtSourceNeededWDTemplate,args = {objektid=idEntity,egenskapsid=idProperty}}
		end
	return iHasSource,tmpResult
end

function txtUnpackReference(frame,iHasSource,tbl)
	if (iHasSource==1) then
		local txt=''
	    for key, tblrow in pairs( tbl ) do
	    	txt=txt..frame:extensionTag("ref", tblrow.content,{ name = tblrow.name}) 
	    	end
		return  txt
		else
		return tbl
		end
end


-- Funktion från https://stackoverflow.com/questions/41942289/display-contents-of-tables-in-lua
function tprint (tbl, indent)
  if not indent then indent = 0 end
  local toprint = string.rep(" ", indent) .. "{\r\n"
  indent = indent + 2 
  for k, v in pairs(tbl) do
    toprint = toprint .. string.rep(" ", indent)
    if (type(k) == "number") then
      toprint = toprint .. "[" .. k .. "] = "
    elseif (type(k) == "string") then
      toprint = toprint  .. k ..  "= "   
    end
    if (type(v) == "number") then
      toprint = toprint .. v .. ",\r\n"
    elseif (type(v) == "string") then
      toprint = toprint .. "\"" .. v .. "\",\r\n"
    elseif (type(v) == "table") then
      toprint = toprint .. tprint(v, indent + 2) .. ",\r\n"
    else
      toprint = toprint .. "\"" .. tostring(v) .. "\",\r\n"
    end
  end
  toprint = toprint .. string.rep(" ", indent-2) .. "}"
  return toprint
end

return p